[RESOLVED] How can i do this...
I've got a big database driven project....15 forms 50+ input boxes and im wondering how to do it effieciently
I've got code to connect to the mysql databse but i dont want to put it inside each form over and over for every form
How can i do it so that i only have to clal one method to connect to the db or leave the db connected constantly from the start of the app. here is the code that i got to put in every form -_-
Code:
Dim conn = New MySqlConnection()
conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=;" & "database=project"
Try
conn.Open()
MessageBox.Show("worked")
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
'conn.Dispose()
End Try
Dim myAdpter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand
Dim sqlquery As String
sqlquery = "insert into Users values (14,'moe','moe70','123456',1);"
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdpter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
If myData.HasRows = 0 Then
TextBox2.Text = "no results"
Else
TextBox2.Text = myData.ToString
End If