After a series of downloading connectors && some plugins, I finally managed to connect xampp to VB.Net. Though I found it very time-consuming/hassle everytime I put a connection string to each form that requires SQL insert and select statements
So I came up with the idea of creating a Class1.vb and place there all the connection strings to xampp. So that everytime I created I new form, all I have to do is to import
Class1.vb to each form so I could access the Dim conn As New MySqlConnection
which as I have mentioned is declared on Class1.vb
Though, somehow I get connected with MYSQL
most of the variables including one that bears the name of the dbtable
cannot be access.
Let me show you what's inside my Class1.vb
Public Class Class1
Dim conn As New MySqlConnection
Dim command As MySqlCommand
Dim reader As MySqlDataReader
Public Sub mysqlConnect()
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format('connectionString for Dbname,server,uid,pword)
Try
conn.Open()
MessageBox.Show("Connected!")
Catch x As Exception
MsgBox(x.Message)
End Try
conn.Close()
end sub
end class
Inside Form1.vb
Public Class Form1
Dim newCon as New Class1
Private Sub Form2_Load
newCon.mysqlConnect()
'Note: mysqlConnect() is a function declared in Class1.vb
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
conn.Open()
Catch x As Exception
End Try
Dim command As New MySqlCommand(String.Format("INSERT STATEMENT"))
command.ExecuteNonQuery()
conn.Close()
End Sub
But the variables I indicate on Button1_Click aren't working. It's as if it cannot read some functions of the Public Sub Connect()
Though, as I have mentioned earlier, the Msgbox("Connected") did work which means that I am totally connected with my DB
.
Any ideas, my friends?
Your comments are appreciated. Thanks in advance.