Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I keep getting this error:

"Number of query values and destination fields are not the same"

I have exactly the same number of fields in my query that are in the database and they are in the same order. I even went so far as to take the parameter values out and substitute hard-coded values and it still throws up. I am not sure what I am doing wrong. Do I have to have a Primary Key for this to work? All this app does is record form data to be exported to a spreadsheet.

Here is my code:

Sub AddRecord()

Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\intranet\databases\results.mdb"

Dim strSQL, strPlant, strTire, strFilter, strWiper As String

Dim objCommand As OleDb.OleDbCommand

Dim objConn As New OleDb.OleDbConnection(strConnString)

'Create SQL String

strSQL = "Insert into PML(Customer, PhoneNo, PlantNo, CarYear, CarMake, CarModel, "

strSQL = strSQL + " DropOff, NeededBy, AirFilter, WiperBlades, Rotation) VALUES "

strSQL = strSQL + " ('Ethel Mertz', '555-5555', '1', 'Toyota', 'Corolla', '2001', "

strSQL = strSQL + " '730'. '430', 'Y', 'N', 'Y')"

objCommand = New OleDb.OleDbCommand(strSQL, objConn)

objConn.Open()

objCommand.ExecuteNonQuery()

objConn.Close()

End Sub

Any help would be appreciated. Thanks

Posted
You can also try putting a break in after you build strSQL and determine exactly what strSQL states. Then copy and paste that into a query in MS Access and then try to execute it. MS Access usually gives better info about the error when you do it that way.
Aspnot

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...