Results 1 to 5 of 5

Thread: How to combine Insert and Where clause together??

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    6

    How to combine Insert and Where clause together??

    Hi, I really need help here...
    I want to update an 'avaibility' as in yes/no in the database..
    Its subjected to only that particular serial number...

    Heres my code.

    Dim cmdTemp As OleDb.OleDbCommand
    cmdTemp = New OleDb.OleDbCommand
    cmdTemp.CommandType = CommandType.Text
    cmdTemp.Connection = cnnRental

    cmdTemp.CommandText = "INSERT INTO Stock (existance) VALUES ('0')"[COLOR=red] <--- how do i add the clause "Where serial = txtSerial.text or '?' to make it to a complete statement?"

    cmdTemp.Connection.Open() cmdTemp.ExecuteNonQuery() cmdTemp.Connection.Close

  2. #2
    New Member
    Join Date
    Aug 2004
    Posts
    5
    Hello,

    if I understand you correctly:

    use UPDATE instad of INSERT.

    VB Code:
    1. UPDATE Stock (existance) VALUES ('0') Where serial = '" & txtSerial.text & "'

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    6
    Hi,
    I tried the following command...
    cmdTemp.CommandText = "UPDATE Stock (existance) VALUES ('false') Where serial_number = '" + txbRentalSerial.Text + "'"

    It gives me "syntax error in Update statement" @@
    Can i use 'false' as the existance is yes/no in access...
    I tried using '0' too... to no avail.. :_(

  4. #4
    New Member
    Join Date
    Aug 2004
    Posts
    5
    try this...


    VB Code:
    1. cmdTemp.CommandText = "UPDATE Stock SET (existance) VALUES ('no') Where serial_number = " & txbRentalSerial.Text

    or

    VB Code:
    1. cmdTemp.CommandText = "UPDATE Stock SET existance='no' Where serial_number = " & txbRentalSerial.Text

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    6
    Thanks Chris,

    cmdTemp.CommandText = "UPDATE Stock SET existance=false Where serial_number = " & LngNumber

    the above command helps... just that i need to make the textbox Clng() before i can pass it in... as i declared serial number as long integer. for the yest/no should put in a true/false instead.

    Thanks a million..

    Regards,
    Henry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width