updates in sybase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teresamakamu
    New Member
    • Oct 2011
    • 5

    updates in sybase

    hi.im trying to update a table in sybase but inserting data from a text box.heres the code

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using Sybase.Data.AseClient;
    
    public partial class _Default : System.Web.UI.Page 
    
    {
        private AseConnection TempDMT_conn = new AseConnection(ConfigurationSettings.AppSettings["connectionString"]);
       
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
    
            string username = txtusername.Text;
            string username2 = txtusername2.Text;
    
            TempDMT_conn.Open();
    
            AseDataAdapter adapter = new AseDataAdapter();
            adapter.MissingMappingAction = MissingMappingAction.Passthrough;
            adapter.MissingSchemaAction = MissingSchemaAction.Add;
            adapter.SelectCommand = new AseCommand(
             "SELECT * FROM login2 WHERE logId > '1234'", TempDMT_conn);
             adapter.UpdateCommand = new AseCommand("UPDATE login2 SET username = @username, " + 
      "password = @password, " +  "WHERE logId = @logId", TempDMT_conn );
    
            adapter.UpdateCommand.UpdatedRowSource =
            UpdateRowSource.None;
            AseParameter parm = new AseParameter("@logId ", AseDbType.Char, 4);
            parm.SourceColumn = "logId ";
            parm.SourceVersion = DataRowVersion.Current;
            adapter.UpdateCommand.Parameters.Add(parm);
    
            AseParameter parm1 = new AseParameter("username ",
            AseDbType.VarChar, 10);
            parm.SourceColumn = "@username ";
            parm.SourceVersion = DataRowVersion.Current;
            adapter.UpdateCommand.Parameters.Add(parm);
            AseParameter parm2 = new AseParameter("password",
            AseDbType.VarChar, 10);
            parm.SourceColumn = "@password ";
            parm.SourceVersion = DataRowVersion.Current;
            adapter.UpdateCommand.Parameters.Add(parm);    
            DataTable dataTable = new DataTable("login2");
            int rowCount = adapter.Fill(dataTable);
    
            foreach (DataRow row in dataTable.Rows)
            {
                row[1] = (string)row[1] + "_Updated";
            }
            int recordsAffected = adapter.Update(dataTable);
    
            dataTable.Clear();
            adapter.SelectCommand.CommandText =
               "SELECT * FROM login2";
            rowCount = adapter.Fill(dataTable);
    
            TempDMT_conn.Close();
        }
    }
    and the errors says:
    Incorrect syntax near the keyword 'WHERE'.



    Line 64: int recordsAffected = adapter.Update( dataTable);

    can anyone please help me.
    Last edited by NeoPa; Nov 2 '11, 02:07 AM. Reason: Added mandatory [CODE] tags for you
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    If I am to guess, it will be this part of your code:

    Code:
    "password = @password, " + "WHERE logId = @logId", TempDMT_conn )
    .

    Try removing the comma after the variable.

    And please try to use the proper tag when posting....

    Good Luck!!!


    ~~ CK

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32663

      #3
      See How to Debug SQL String.

      You need to include the current contents of dataTable in your question.

      Comment

      Working...