I can not seem to find the problem in the following snippet of code. I would like the code to insert data into the Ms Database. I get an error message as follows.

System.Data.OleDb.OleDbException was unhandled
Message="No value given for one or more required parameters."
Below is the code for the application

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Create containers to contain Text

Dim myLastName As String

Dim myFirstName As String

Dim myTELUSID As String

Dim myWork As String

Dim myCell As String

Dim myEmailAddress As String

'Fill the new containers with data the user keys in

myLastName = TextBox1.Text

myFirstName = TextBox2.Text

myTELUSID = TextBox3.Text

myWork = TextBox4.Text

myCell = TextBox5.Text

myEmailAddress = TextBox6.Text

'Open database connection and prepare to add records

'Dim MyConn As New ADODB.Connection

Dim strConn As String

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source= e:\GDPR-OPE.MDB;"

'MyConn.Open(strConn) 'opens database command

'now add the command to execute the database add

Dim SQL As String = "INSERT INTO tblEmployees"

SQL = SQL + "(LastName,FirstName,TELUSID,Work_Number,Cell_Number,EmailAddress)"

SQL = SQL + "values("

SQL = SQL + "myLastName,myFirstName,myTELUSID,myWork,myCell,myEmailAddress)"

Dim myconn As New OleDbCommand((SQL), New OleDbConnection(strConn))




Re: .NET Framework Data Access and Storage Problen Inserting Data into a Ms Database


You are not passing from your variables to the SQL statement. You specified variables names inside of the query, but provider has no idea what that means. You need to define parameters for your SQL statement and then pass values from the variables to those parameters. See next link with the sample of parameterized queries