Re: Student/Developer NEW to MySQL and VB.NET seeking help desperately on connectivity and querries
Posted by: David
Date: November 08, 2004 08:53AM

Here's a simple example to get you started.

Dim conn As New MySql.Data.MySqlClient.MySqlConnection("Database=blah;Data Source=blah blah;User Id=username;Password=password;")

Dim cmd As New MySql.Data.MySqlClient.MySqlCommand("SELECT fname, lname FROM names;", conn)
Dim myReader As New MySql.Data.MySqlClient.MySqlDataReader

Try

conn.Open()
myReader = cmd.ExecuteReader()

While myReader.Read()

TextBox1.Text = myReader.Item("fname")
TextBox2.Text = myReader.Item("lname")

End While

Catch ex As Exception

do something with your exception, if necessary

Finally

myReader.Close()
conn.Close()

End Try

The reader reads one line at a time from your datasource when you call the myReader.Read() method. It stores the values in a list that you can access via the myReader.Item("field name") method. In the above example, I'm looping through the datareader one line at a time, and putting the values of fname and lname into the textboxes. This assumes that you have a table in your database that contains fname and lname as fields.

This sounds more like a .NET question than a MySQL question, though. If you can establish a connection to your database and construct a valid query, MySQL's work is basically done within the context of your application. The rest of your code pertains to happenings in .NET. Might I suggest that you visit http://asp.net for answers to .NET specific questions? Although the site is geared toward Web development, as far as data manipulation in your applications, there isn't much that's different. The site also has links to other places that are dedicated to .NET development.

Good luck with your application,

David

Options: ReplyQuote




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.