Results 1 to 4 of 4

Thread: Sql statement error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    Sql statement error

    Hi Is there an error in my sql update statement here?
    I am trying to read, adjust and write back to the same cell in a database. I think I can do it like this but i get an error on the executenonquery line.

    Code:
    Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConn2)
            conn1.Open()
            Dim cmd As New System.Data.OleDb.OleDbCommand()
            cmd.Connection = conn1
            cmd.CommandText = "SELECT " & Night & " FROM TblContacts WHERE Phone='" & incomingtextno & "'"
            Dim myOleDbCommand As New OleDbCommand(cmd.CommandText, cmd.Connection)
    
            Using myDataReader As OleDbDataReader = myOleDbCommand.ExecuteReader()
    
                If myDataReader.HasRows() Then
    
                    While myDataReader.Read()
                        current_count = myDataReader.Item(Night).ToString + vbCrLf
                        TxtEventLog.Text = current_count
                        current_count = current_count + Quantity
                        cmd.CommandText = "UPDATE TblContacts SET " & Night & "='" & current_count & "' Where Phone='" & incomingtextno & "'"
                        cmd.ExecuteNonQuery()
                        ' index = index + 1
    
                        notfound = 0
                    End While
                Else
                    notfound = 1
                    ' Address_text.Text = "Not Found"
                End If
            End Using
            con.Close()

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Sql statement error

    What is the error message ?
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    Re: Sql statement error

    The error is on the ExecuteNonQuery line and is
    "Data type mismatch in criteria expression."

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Sql statement error

    This could be the case where you include your values within '' which is not required. Use the parameters as suggested here
    Please mark you thread resolved using the Thread Tools as shown

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