Mysql and VB.net

vramia

New member
Joined
Jun 29, 2006
Messages
2
Programming Experience
1-3
i have teh code where it connects to mysql and now i need to get the data from it and write it to a table this is my code:

VB.NET:
Imports MySql.Data.MySqlClient
Imports System.Data
 
 
 
Public Class frmForm1
Dim conn As MySqlConnection
 
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Application.Exit()
End Sub
 
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
conn = New MySqlConnection()
conn.ConnectionString = "server=" & txtServer.Text & ";" _
& "user id=" & txtUsername.Text & ";" _
& "password=" & txtPassword.Text & ";" _
& "database=bugs"
'MessageBox.Show(conn.ConnectionString)
Try
conn.Open()
'Dim DBConnection As New MySql.Data.MySqlClient.MySqlConnection(conn.ConnectionString)
'Dim SelectProducts As New MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM attachments")
'Dim NWAdaptor As New MySql.Data.MySqlClient.MySqlDataAdapter(SelectProducts)
'NWAdaptor.SelectCommand.Connection = DBConnection
 
'Dim ds As New Data.DataSet
'NWAdaptor.Fill(ds, "attachments")
'' nwadaptor.
 
'Dim DataSource = ds
'MessageBox.Show(ds.ToString())
'Dim DataMember = "attachments"
Call ReadMyData(conn.ConnectionString)
MessageBox.Show("Connection Opened Successfully")
 
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub
 
Public Sub ReadMyData(ByVal myConnString As String)
' MessageBox.Show(myConnString)
Dim mySelectQuery As String = "SELECT * FROM bugs_activity"
Dim myConnection As New MySqlConnection(myConnString)
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myReader As Data.IDataReader = myCommand.ExecuteReader()
Try
While myReader.Read()
Console.WriteLine((myReader.GetInt32(0).ToString & ", " & myReader.GetString(1)))
MessageBox.Show(myReader.GetInt32(0).ToString)
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
myConnection.Close()
End Try
End Sub 'ReadMyData
 
End Class

i was trying to write the contant of the tabels to the screen but it is not working. could anyone help. thank you
 
Last edited by a moderator:
Please use CODE tags for better readability (see forum FAQ), there is also code-tag button in advanced posting editor. Also moved your post from Database General forum to MySql forum.

Your namespace is MySql.Data.MySqlClient which is the same Connector/Net uses. I don't know if other suites use the same namespace.

Your connectionstring looks like it's wrong (if I'm right :)). If you check with www.connectionstrings.com click MySql and click Connector/Net you'll see where you do 'user id=' and 'password=' they use 'uid=' and 'pwd='.
 
Back
Top