Invalid attempt to access a field before calling Read() INSERT

Posted by Raphael Fernandes on Stack Overflow See other posts from Stack Overflow or by Raphael Fernandes
Published on 2012-10-24T04:55:41Z Indexed on 2012/10/24 5:01 UTC
Read the original article Hit count: 98

Filed under:
|

I'm trying to use this code to check if the system already exists a field with this value

Dim adap As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM client WHERE code ='"+ TxtCode.Text +"'"
                Dim comand As New MySqlCommand()
                comand.Connection = con
                comand.CommandText = sqlquery
                adap.SelectCommand = comand
                Dim data As MySqlDataReader
                data = comando2.ExecuteReader()
                leitor.Read()
                If (data(3).ToString) = code Then
                    MsgBox("already exists", MsgBoxStyle.Information)
                    TxtCode.ResetText()
                    TxtCode.Focus()
                Else
                    Console.WriteLine(insert("INSERT INTO client (name, tel, code) VALUES ('" & name & "', '" & tel & "')"))
                    con.Close()
                End If

© Stack Overflow or respective owner

Related posts about mysql

Related posts about vb.net