|
|
Question : MySQL in VB.NET select statement ?
|
|
Hello:
I am just starting out with MySQL and am working with VB.NET in a windows form.
My question is how do I handle my select statement not returning a value?
An example would be if I want to find out if there is a persons name in the database, if its not located then i want to execute some more code. Right now I just receive an error message that the name wasn't found.
What is the syntax for handling a record that is not found in a simple select statement when working in VB.NET?
Thank you for your time.
|
Answer : MySQL in VB.NET select statement ?
|
|
Check the other thread for the ON DUPLICATE KEY clause, because I think that is what you really want. Of course, you can do this in VB with
Dim conn as new MySqlConnection("xxxxxxxxxxx") Dim sql as String = "SELECT Name FROM MasterList WHERE Name = '" & LastName & "'" Dim adapter As New MySqlDataAdapter() adapter.SelectCommand = new MySqlCommand(sql, conn) adapter.Fill(dataset) if dataset.tables("MasterList").rows.count = 0 then sql= "UPDATE MasterList SET CDate='" & CurrentDate & "' WHERE Name = '" & LastName & "'" else sql = "INSERT INTO MasterList SET " & _ "Name='" & LastName & "'," & _ "First='" & FirstName & "'," & _ "CDate='" & CurrentDate & "'" & _ endif dim anothercommand as new mysqlcommand(sql.conn) anothercommand.executenonquery
|
|
|
|
|