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:
i was trying to write the contant of the tabels to the screen but it is not working. could anyone help. thank you
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: