MySQL Forums
Forum List  »  Connector/ODBC

VB.NET & MySQL - A few problems
Posted by: Dan Cunningham
Date: April 06, 2005 07:06AM

Hi Guys,
I have a few questions about using MySQL with VB.NET. Well, they may actually be considered ODBC connections but please bear with me - I'm new to both VB.NET and any sort of data access! :)

Ok, so firstly, I'm connecting up to my MySQL DB fine and returning information. I do this with a while loop. My code looks something like this:

'Query
MyCommand.CommandText = "SELECT * FROM workstation_info WHERE Computer_Name = '" & tbxComputerSearch.Text & "'"

'Execute(Query)
Dim MyDataReader As OdbcDataReader

MyDataReader = MyCommand.ExecuteReader

While MyDataReader.Read
lnkSerialNumber.Text = CStr(MyDataReader("Serial_number"))
End While

This is fine if I only have one record where Computer_Name = blah, but if two are the same, the while loop will run through each record and only display the last one. Is there a way I can check through the amount of rows after the query and let the end user select which record they want to view? I'm sure this is probably simple, I'm a newb tho :O

Secondly, I need to display an error if no rows are returned. I've tried adding this into the while loop:

If MyDataReader("computer_name") Is DBNull.Value Then
MsgBox("Computer Name not found!", MsgBoxStyle.Exclamation)
Exit While
End If

But this doesnt seem to do much for me. Is there another way I can do this?

Any help is appreciated, and apologies for asking probably simple questions!

Thanks, Dan.

Options: ReplyQuote


Subject
Written By
Posted
VB.NET & MySQL - A few problems
April 06, 2005 07:06AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.