Pokusavam da rijesim jedan problem, ali nisam uspeo pomocu Google-a, pa vas molim za pomoc. Naime, treba da uspostavim konekciju sa MySQL bazom preko VB 2008, i da podatke iz celije prikazem na TextBox1.
Imam sledeci code (ovo sam izgooglao):
Code:
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySqlConnection As MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = "server=localhost; user id=root; password=basepass; database=opendb;"
Try
MySqlConnection.Open()
MessageBox.Show("Connection to Database has been opened.")
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT state FROM reminder WHERE id = '1';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquary
myadapter.SelectCommand = command
Dim mydata As MySqlDataReader
mydata = command.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("Ne postoji takav korisnik!", MsgBoxStyle.Information)
Else
MsgBox("Welcome user", MsgBoxStyle.Information)
TextBox1.Text = ???????????
End If
End Sub
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySqlConnection As MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MySqlConnection = New MySqlConnection()
MySqlConnection.ConnectionString = "server=localhost; user id=root; password=basepass; database=opendb;"
Try
MySqlConnection.Open()
MessageBox.Show("Connection to Database has been opened.")
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT state FROM reminder WHERE id = '1';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquary
myadapter.SelectCommand = command
Dim mydata As MySqlDataReader
mydata = command.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("Ne postoji takav korisnik!", MsgBoxStyle.Information)
Else
MsgBox("Welcome user", MsgBoxStyle.Information)
TextBox1.Text = ???????????
End If
End Sub
Ok, podesio sam driver za konekciju na bazu i dobijem poruku da se aplikacija uspesno povezala na bazu. Dobijem i poruku "Welcome user", dakle pronasao je i podatke u bazi. Ono sto mi ne polazi za rukom, i trebalo bi da je jednostavno, jeste kako sad da sadrzaj te celije ispisem u TextBox1.
Hvala unapred.