Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > How to use the mysql connection from another form?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2012, 07:34 AM
xdra90 xdra90 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 1
Default 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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->