08-29-2012, 10:42 AM
Guys,
I'm having problems with my MySQL query. VB keeps throwing the following exception:
Here's the code I'm using:
[code2=vbnet]Dim dbConn As New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=parts;Password=parts;Database=accounting")
Dim dbQuery As String = ""
Dim dbData As MySqlDataReader
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
Try
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
Else
dbConn.Open()
dbCmd.CommandText = dbQuery
dbCmd.Connection = dbConn
dbAdapter.SelectCommand = dbCmd
dbData = dbCmd.ExecuteReader
dbQuery = "INSERT INTO customer (accountNumber, nameLAST, nameFIRST, nameCOMPANY, addressSTREET, addressSTREET1, addressCITY, addressSTATE, addressZIPCODE, phone, fax, email) VALUES('" & TextBoxAccount.Text & "','" & TextBoxLastName.Text & "','" & TextBoxFirstName.Text & "','" & TextBoxCompanyName.Text & "','" & TextBoxAddress1.Text & "','" & TextBoxAddress2.Text & "','" & TextBoxCity.Text & "','" & ComboBoxState.SelectedItem & "','" & MaskedTextBoxZip.Text & "','" & MaskedTextBoxPhone.Text & "','" & MaskedTextBoxFax.Text & "','" & TextBoxEmail.Text & "')"
End If
Catch ex As MySqlException
MessageBox.Show("Error connecting to database server. Please call the IT/Systems Helpdesk for support." & vbCrLf & vbCrLf & ex.ToString)
End Try
dbConn.Close()[/code2]
Your help would be greatly appreciated, thanks.
I'm having problems with my MySQL query. VB keeps throwing the following exception:
Quote:The CommandText property has not been properly initialized
Here's the code I'm using:
[code2=vbnet]Dim dbConn As New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=parts;Password=parts;Database=accounting")
Dim dbQuery As String = ""
Dim dbData As MySqlDataReader
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
Try
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
Else
dbConn.Open()
dbCmd.CommandText = dbQuery
dbCmd.Connection = dbConn
dbAdapter.SelectCommand = dbCmd
dbData = dbCmd.ExecuteReader
dbQuery = "INSERT INTO customer (accountNumber, nameLAST, nameFIRST, nameCOMPANY, addressSTREET, addressSTREET1, addressCITY, addressSTATE, addressZIPCODE, phone, fax, email) VALUES('" & TextBoxAccount.Text & "','" & TextBoxLastName.Text & "','" & TextBoxFirstName.Text & "','" & TextBoxCompanyName.Text & "','" & TextBoxAddress1.Text & "','" & TextBoxAddress2.Text & "','" & TextBoxCity.Text & "','" & ComboBoxState.SelectedItem & "','" & MaskedTextBoxZip.Text & "','" & MaskedTextBoxPhone.Text & "','" & MaskedTextBoxFax.Text & "','" & TextBoxEmail.Text & "')"
End If
Catch ex As MySqlException
MessageBox.Show("Error connecting to database server. Please call the IT/Systems Helpdesk for support." & vbCrLf & vbCrLf & ex.ToString)
End Try
dbConn.Close()[/code2]
Your help would be greatly appreciated, thanks.
//Kismet