update statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wassssup
    New Member
    • Oct 2007
    • 47

    #1

    update statement

    hi..i would like to ask whats wrong with this piece of code...
    [code=vbnet]
    int convertNumber;
    string label, doID = "1";

    label = doNumberLabel.T ext;
    convertNumber = int.Parse(label );

    string connection = "provider=Micro soft.jet.OLEDB. 4.0;Data source=" + Application.Sta rtupPath + "\\..\\..\\fypS tock.mdb; Jet OLEDB:Database Password=" + databasePasswor d;
    OleDbConnection myConnection = new OleDbConnection (connection);
    myConnection.Op en();

    string query = @"update doNumber set Number= '" + convertNumber +
    "' WHERE numberID = " + doID;

    myCommand = new OleDbCommand();
    myCommand.Comma ndText = query;
    myCommand.Conne ction = myConnection;
    myCommand.Execu teNonQuery();

    myConnection.Cl ose();
    [/code]
    in the database, numberID is auto number and Number is Number.
    what i'm trying to do id to get the value from label donumberlabel, then converrt it to string, then put the string into the database.

    the error is it highlight the "myCommand.Exec uteNonQuery();" then says error on the update statement.
    i'm using C#

    please help
    Last edited by debasisdas; Dec 26 '07, 08:44 AM. Reason: Formatted using code tags
  • CyberSoftHari
    Recognized Expert Contributor
    • Sep 2007
    • 488

    #2
    [CODE=]string query = @"update doNumber set Number= '" + convertNumber +
    "' WHERE numberID = " + doID;[/CODE]

    Check the query! the convertnumber is in integer type and what is the type of Number in database you had given?
    Note : Youre passing convertNumber as string.

    Comment

    • wassssup
      New Member
      • Oct 2007
      • 47

      #3
      Originally posted by CyberSoftHari
      Check the query! the convertnumber is in integer type and what is the type of Number in database you had given?
      Note : Youre passing convertNumber as string.
      my Number in database is number in the data type column
      but i declare convertNumber as int already..

      Comment

      • CyberSoftHari
        Recognized Expert Contributor
        • Sep 2007
        • 488

        #4
        Check the query string properly, you are passing the int type curNumber with single quote (which means you are passing as string value) and as well doiD without single quote (which means passing as number type).
        Last edited by CyberSoftHari; Dec 26 '07, 03:32 AM. Reason: and as ...

        Comment

        Working...