1 Replies - 3802 Views - Last Post: 25 February 2009 - 11:25 PM Rate Topic: -----

#1 concourse   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-January 09

vb.net & mysql connection problem

Post icon  Posted 25 February 2009 - 11:01 PM

hello everyone
i am new in vb.net programming.
i want to connect database from mysql 5.1 with vb.net 2008 plz guide me.
should i use some tool to connect to database? if yes then which one???
which import file should i use?
i am not getting mysql name in data -> add new data sourse and in server explorer also.
plz give me the steps to make the connection.
Is This A Good Question/Topic? 0
  • +

Replies To: vb.net & mysql connection problem

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: vb.net & mysql connection problem

Posted 25 February 2009 - 11:25 PM

Ok, normally we dont do this but tonigt I'm feeling a little generous. Here's an example of connecting with MySQL with the MySQL Connector. This example shows how to connect and do a simple select statement from a sample table

''' <summary>
''' Method for connection to a mySQL database. You
''' need to download the mySQL Connector located at
''' http://dev.mysql.com/downloads/connector/net/1.0.html]
''' 
''' NOTE: I am a big supporter of having the connection
''' stored in the web.config, not inline like this
''' </summary>
''' <param name="server"></param>
Private Sub connectoToMySql(ByVal server As String)
	'set your connection string. 
	'NOTE: I am a big supporter of having the connection
	'stored in the web.config, not inline like this
	Dim connString As String = "SERVER=" + server + ";" + "DATABASE=mydatabase;" + "UID=testuser;" + "PASSWORD=testpassword;"
	'create your mySQL connection
	Dim cnMySQL As New MySqlConnection(connString)
	'create your mySql command object
	Dim cmdMySQL As MySqlCommand = cnMySQL.CreateCommand()
	'create your mySQL reeader object
	Dim reader As MySqlDataReader
	'set the command text (query) of the
	'mySQL command object
	cmdMySQL.CommandText = "select * from mycustomers"
	'open the mySQL connection
	cnMySQL.Open()
	'execute the reader, thus retrieving the data
	reader = cmdMySQL.ExecuteReader()
	'while theres data keep reading
	While reader.Read()
		Dim thisrow As String = ""
		For i As Integer = 0 To reader.FieldCount - 1
			thisrow += reader.GetValue(i).ToString() + ","
		Next
		listBox1.Items.Add(thisrow)
	End While
	cnMySQL.Close()
End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1