Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with creating an INSERT statement using MySQL
#1
Guys,

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


Messages In This Thread
Help with creating an INSERT statement using MySQL - by kismetgerald - 08-29-2012, 10:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 33,032 04-12-2013, 06:27 PM
Last Post: brandonio21
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,855 11-28-2012, 05:19 PM
Last Post: brandonio21
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 43,302 10-18-2012, 07:16 PM
Last Post: brandonio21
  How do I fill my form with MySQL data based on Combobox? kismetgerald 8 26,704 10-14-2012, 09:05 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,045 08-13-2012, 08:58 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 22,379 07-26-2012, 03:44 PM
Last Post: Moldraxian
  How to Package MySql Connector and MySql Program? Moldraxian 3 14,754 07-20-2012, 12:23 PM
Last Post: brandonio21
  MySql Help Blackrobot 3 14,615 04-06-2012, 03:49 AM
Last Post: xolara
  VB and MySQL help please Chad1020 2 12,248 03-21-2012, 04:10 PM
Last Post: brandonio21
  MySQL Help -Kid- 6 25,400 02-20-2012, 11:57 AM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)