vb codes for sql update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alfeena
    New Member
    • Apr 2008
    • 4

    vb codes for sql update

    i'm not sure whether this shud b in vb or sql but i'm havin a problem with updating the data in access using the sql commands in vb. It seems that it will not update but no error messages were shown. So i'm simply lost in verifying the error. Here is a sample for my code:

    strDate = Format(txtInvoi ceDate.Text, "dd/mm/yyyy")

    If saveType = 2 Then ' New Record

    strSQL = "INSERT INTO tb_GTotalFL (InvoiceDate,Ac cNo,Discount,Ta x) " _
    & "VALUES ('" & txtInvoiceDate. Text & "'," _
    & "'" & txtAccNo.Text & "'," _
    & "" & txtDiscount.Tex t & "," _
    & "'" & txtTax.Text & "')"
    Else
    'Edit Record
    strSQL = "UPDATE tb_GTotalFL SET Discount=" & txtDiscount.Tex t & ", " _
    & " Tax=" & txtTax.Text & "" _
    & " WHERE AccNo='" & txtAccNo.Text & "' AND InvoiceDate= #" & strDate & "#"
    End If
    ' Open a connection using OLEDB.
    cnn.ConnectionS tring = VDataFile
    cnn.Open
    Set rs = cnn.Execute(str SQL)
    'close connection
    Set rs = nothing
    Set cnn = nothing
    cnn.close

    ...no errors..but wont update record edited..can any1 advice..? help is very much appreciated
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Originally posted by alfeena
    i'm not sure whether this shud b in vb or sql but i'm havin a problem with updating the data in access using the sql commands in vb. It seems that it will not update but no error messages were shown. So i'm simply lost in verifying the error. Here is a sample for my code:

    strDate = Format(txtInvoi ceDate.Text, "dd/mm/yyyy")

    If saveType = 2 Then ' New Record

    strSQL = "INSERT INTO tb_GTotalFL (InvoiceDate,Ac cNo,Discount,Ta x) " _
    & "VALUES ('" & txtInvoiceDate. Text & "'," _
    & "'" & txtAccNo.Text & "'," _
    & "" & txtDiscount.Tex t & "," _
    & "'" & txtTax.Text & "')"
    Else
    'Edit Record
    strSQL = "UPDATE tb_GTotalFL SET Discount=" & txtDiscount.Tex t & ", " _
    & " Tax=" & txtTax.Text & "" _
    & " WHERE AccNo='" & txtAccNo.Text & "' AND InvoiceDate= #" & strDate & "#"
    End If
    ' Open a connection using OLEDB.
    cnn.ConnectionS tring = VDataFile
    cnn.Open
    Set rs = cnn.Execute(str SQL)
    'close connection
    Set rs = nothing
    Set cnn = nothing
    cnn.close

    ...no errors..but wont update record edited..can any1 advice..? help is very much appreciated
    are you using vb6??
    Im not to familiar with vb6 if you are using a later version use snippets

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      try like this
      [code=vb]
      cnn.BeginTrans
      cnn.execute "Your insert or update SQL query here."
      cnn.CommitTrans[/code]

      Comment

      • alfeena
        New Member
        • Apr 2008
        • 4

        #4
        thx 4 the feedback..final ly solved the problem..it seems that my date format is whats causing the problem. So i changed the format to (mm/dd/yyyy) n am able to update the records..thx again!

        Comment

        Working...