I am sorry to begin another thread on this, however I have a deadline that is ever approaching and I have yet to find the solution.
If I run this code, I get an error stating that the amount of values that are being sent is not the same to the number of fields in the DB.
The only field that will not be updated by this query is the auto number customerID, thus there is no need to declare it.
I have tried many suggestions from varying people and all have failed.
It is worth mentioning that if i remove the auto number field then the query works perfectly.
Help!!
Thanks in advanced
Graham
If I run this code, I get an error stating that the amount of values that are being sent is not the same to the number of fields in the DB.
The only field that will not be updated by this query is the auto number customerID, thus there is no need to declare it.
I have tried many suggestions from varying people and all have failed.
It is worth mentioning that if i remove the auto number field then the query works perfectly.
Help!!
Thanks in advanced
Graham
VB.NET:
'creates storage variables for the input fields
Dim title As String = titleList.Text
Dim firstname As String = firstnameText.Text
Dim surname As String = surnameText.Text
Dim houseNo As String = housenoText.Text
Dim address1 As String = address1Text.Text
Dim address2 As String = address2Text.Text
Dim county As String = countyComboBox.Text
Dim postcode As String = postcode1Text.Text
Dim DofBday As Integer = dayList.Text
Dim DofBmonth As String = monthList.Text
Dim DofByear As Integer = yearText.Text
Dim telephone As String = telephoneText.Text
' Creates the OleDb connection
Dim connect As New OleDb.OleDbConnection
connect.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Holiday.mdb"
'Creates a variable to store the sql ? says look for the value in the parameter
Dim sql As String = "INSERT INTO tblCustomer VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"
'Creates a variable command so that the sql and connection variables are run
Dim command As New System.Data.OleDb.OleDbCommand(sql, connect)
'insted of using a concat use the param value
command.Parameters.AddWithValue("@Title", title)
command.Parameters.AddWithValue("@firstname", firstname)
command.Parameters.AddWithValue("@surname", surname)
command.Parameters.AddWithValue("@houseNo", houseNo)
command.Parameters.AddWithValue("@address1", address1)
command.Parameters.AddWithValue("@address2", address2)
command.Parameters.AddWithValue("@county", county)
command.Parameters.AddWithValue("@postcode", postcode)
command.Parameters.AddWithValue("@DofBday", DofBday)
command.Parameters.AddWithValue("@DofBmonth", DofBmonth)
command.Parameters.AddWithValue("@DofByear", DofByear)
command.Parameters.AddWithValue("@telephone", telephone)
'opens connection
connect.Open()
MsgBox("A Connection to the Database is now open")
'runs the command variable
command.ExecuteNonQuery()
'closes connection
connect.Close()
MsgBox("The Connection to the Database is now Closed")
Me.Close()