Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Update Query Error

Update Query Error

Scheduled Pinned Locked Moved Visual Basic
databasehelpannouncement
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gagan 20
    wrote on last edited by
    #1

    Hi all... When I execute update query, I get error "data type mismatch in criteria expression" I used following code :

    Try
    DBConnection.connect() 'code to open database.
    Dim sql As String = "update MortgageDetails set [Borrower_Name]='" & txtBorrowerName.Text & "', [Caste]='" & txtCaste.Text & "', " & _
    "[Area]='" & txtArea.Text & "', [Address]='" & txtAddress.Text & "', [Product_Detail]='" & txtProductDetail.Text & "', " & _
    "[Current_Date]='" & txtCurrentDate.Text & "',[Current_Value]=" & txtProductValue.Text & "," & _
    "[Amount_Borrowed]=" & txtAmountBorrowed.Text & " where [S_No]=" & txtSNo.Text

            Dim cmd As New OleDbCommand(sql, con)
            cmd.ExecuteNonQuery()
            MsgBox("Record Updated!", MsgBoxStyle.Information)
            Me.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    

    I am using VB2008 and MS Access 2003 as database. Suggest me what to do. Thanks. Gagan

    S L L 3 Replies Last reply
    0
    • G Gagan 20

      Hi all... When I execute update query, I get error "data type mismatch in criteria expression" I used following code :

      Try
      DBConnection.connect() 'code to open database.
      Dim sql As String = "update MortgageDetails set [Borrower_Name]='" & txtBorrowerName.Text & "', [Caste]='" & txtCaste.Text & "', " & _
      "[Area]='" & txtArea.Text & "', [Address]='" & txtAddress.Text & "', [Product_Detail]='" & txtProductDetail.Text & "', " & _
      "[Current_Date]='" & txtCurrentDate.Text & "',[Current_Value]=" & txtProductValue.Text & "," & _
      "[Amount_Borrowed]=" & txtAmountBorrowed.Text & " where [S_No]=" & txtSNo.Text

              Dim cmd As New OleDbCommand(sql, con)
              cmd.ExecuteNonQuery()
              MsgBox("Record Updated!", MsgBoxStyle.Information)
              Me.Close()
          Catch ex As Exception
              MsgBox(ex.Message)
          End Try
      

      I am using VB2008 and MS Access 2003 as database. Suggest me what to do. Thanks. Gagan

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      Sounds like you are passing some data to the table as text when it should be numeric or some other non string format but without seeing your table definition its hard to say something else.

      Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

      1 Reply Last reply
      0
      • G Gagan 20

        Hi all... When I execute update query, I get error "data type mismatch in criteria expression" I used following code :

        Try
        DBConnection.connect() 'code to open database.
        Dim sql As String = "update MortgageDetails set [Borrower_Name]='" & txtBorrowerName.Text & "', [Caste]='" & txtCaste.Text & "', " & _
        "[Area]='" & txtArea.Text & "', [Address]='" & txtAddress.Text & "', [Product_Detail]='" & txtProductDetail.Text & "', " & _
        "[Current_Date]='" & txtCurrentDate.Text & "',[Current_Value]=" & txtProductValue.Text & "," & _
        "[Amount_Borrowed]=" & txtAmountBorrowed.Text & " where [S_No]=" & txtSNo.Text

                Dim cmd As New OleDbCommand(sql, con)
                cmd.ExecuteNonQuery()
                MsgBox("Record Updated!", MsgBoxStyle.Information)
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        

        I am using VB2008 and MS Access 2003 as database. Suggest me what to do. Thanks. Gagan

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Passing literal data like that always is asking for trouble. The exact problem is most likely the date you have there. Passing dates and other non-string types depends on the exact database you use, and is often problematic. Suggestion: 1. use programming variables, and TryParse() your textual input before passing the info to the database; this traps input errors and avoids SQL injection; 2. use SqlParameter and pass the above variables; don't use literals in SQL. In will take a bit more code, but the result will be much more robust. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        1 Reply Last reply
        0
        • G Gagan 20

          Hi all... When I execute update query, I get error "data type mismatch in criteria expression" I used following code :

          Try
          DBConnection.connect() 'code to open database.
          Dim sql As String = "update MortgageDetails set [Borrower_Name]='" & txtBorrowerName.Text & "', [Caste]='" & txtCaste.Text & "', " & _
          "[Area]='" & txtArea.Text & "', [Address]='" & txtAddress.Text & "', [Product_Detail]='" & txtProductDetail.Text & "', " & _
          "[Current_Date]='" & txtCurrentDate.Text & "',[Current_Value]=" & txtProductValue.Text & "," & _
          "[Amount_Borrowed]=" & txtAmountBorrowed.Text & " where [S_No]=" & txtSNo.Text

                  Dim cmd As New OleDbCommand(sql, con)
                  cmd.ExecuteNonQuery()
                  MsgBox("Record Updated!", MsgBoxStyle.Information)
                  Me.Close()
              Catch ex As Exception
                  MsgBox(ex.Message)
              End Try
          

          I am using VB2008 and MS Access 2003 as database. Suggest me what to do. Thanks. Gagan

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Seems the problems is with this piece of code:

          "[Current_Date]='" & txtCurrentDate.Text & "'"

          Access expects dates to be passed in a specific format, try this:

          "[Current_Date]=#" & Convert.ToDateTime(txtCurrentDate.Text).ToString("MM/DD/YYYY") & "#"

          G 1 Reply Last reply
          0
          • L Lost User

            Seems the problems is with this piece of code:

            "[Current_Date]='" & txtCurrentDate.Text & "'"

            Access expects dates to be passed in a specific format, try this:

            "[Current_Date]=#" & Convert.ToDateTime(txtCurrentDate.Text).ToString("MM/DD/YYYY") & "#"

            G Offline
            G Offline
            Gagan 20
            wrote on last edited by
            #5

            Thanks for your answer. It worked.

            L 1 Reply Last reply
            0
            • G Gagan 20

              Thanks for your answer. It worked.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You're welcome. Please mark it as answer so your post doesn't appear unanswered.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups