
06-27-2012, 07:34 AM
|
|
Newcomer
|
|
Join Date: Jun 2012
Posts: 1
|
|
How to use the mysql connection from another form?
|
Hi, I need some help at a code.
I have 2 forms on my application.I want to connect to a mysql database from the first form, then hide the form and show the 2nd form where I can insert sql records.
So here's the code in the 1st form :
Code:
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cs As String = "Database=accounter;Data Source=" & TextBox1.Text & ";" _
& "User Id=" & TextBox2.Text & ";" & "Password=" & TextBox3.Text
Dim conn As New MySqlConnection(cs)
If TextBox1.Text = String.Empty Or TextBox2.Text = String.Empty Or TextBox3.Text = String.Empty Then
MsgBox("Nici o casuta nu poate fi goala.")
Else
Try
conn.Open()
Form2.Show()
Me.Hide()
Catch ex As MySqlException
MsgBox("Eroare: " & ex.ToString())
End Try
End If
End Sub
End Class
And i need the code for the 2nd form...
Thanks http://4metin.ro/images/smilies/67.gif http://4metin.ro/images/smilies/115.gif
|
|