Select doesnt work. Mysql
Hello I'm doing an app in VB.Net 2005 using the .net connector. For the moment it connects but I can't execute a SELECT, the dataset returns empty, count = 0. This is the code I use:
Private Sub BBaseDatos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBaseDatos.Click
Dim t As New System.Data.DataSet
Dim sql As String
Dim da As New MySqlDataAdapter
Dim conn = New MySqlConnection()
conn.ConnectionString = "server=localhost;" _
& "user id=root;" _
& "password='';" _
& "database=cima"
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
sql = "SELECT ID_ES, NOMBRE_ES FROM estacion"
da.SelectCommand = New MySqlCommand(sql, conn)
da.Fill(t)
'conn.Close()
Me.DataGridView1.DataSource = t
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub
I have a DataGridView in the mainform, but I don't use databindings. Can someone help me? Thanks
[1326 byte] By [
fonx] at [2007-11-20 10:43:08]

# 1 Re: Select doesnt work. Mysql
Well I got it, I found valious information in a sticky post about tutorials. This is the new procedure with some changes
Private Sub BBaseDatos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BBaseDatos.Click
Dim sql As String
Dim myData As New DataTable
Dim myAdapter As New MySqlDataAdapter
Dim conn = New MySqlConnection
Dim myCommand As New MySqlCommand
conn.ConnectionString = "server=localhost;" _
& "user id=root;" _
& "password='';" _
& "database=cima"
Try
conn.Open()
'MessageBox.Show("Connection Opened Successfully")
sql = "SELECT ID_ES, NOMBRE_ES FROM estacion"
myCommand.Connection = conn
myCommand.CommandText = sql
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
conn.Close()
Me.DataGridView1.DataSource = myData
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub
fonx at 2007-11-10 3:08:33 >
