ASP.NET/VB/SQL: trying to insert data, getting error "no value given for required parameters"
Posted
by
Sara
on Stack Overflow
See other posts from Stack Overflow
or by Sara
Published on 2011-01-14T19:34:14Z
Indexed on
2011/01/14
19:53 UTC
Read the original article
Hit count: 201
I am pretty sure this is a basic syntax error, I am new at this and basically figuring things out by trial and error... I am trying to insert data from textboxes into an Access database, where the primary key fields in tableCourse are prefix and course_number. It keeps giving me the "no value given for one or more required parameters" error. Here is my codebehind:
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
'Collect Data
Dim myDept = txtDept.Text
Dim myFirst = txtFirstName.Text
Dim myLast = txtLastName.Text
Dim myPrefix = txtCoursePrefix.Text
Dim myNum = txtCourseNum.Text
'Define Connection
Dim myConn As New OleDbConnection
myConn.ConnectionString = AccessDataSource1.ConnectionString
'Create commands
Dim myIns1 As New OleDbCommand("INSERT INTO tableCourse (department, name_first, name_last, prefix, course_number) VALUES (@myDept, @myFirst, @myLast, @myPrefix, @myNum)", myConn)
'Execute the commands
myConn.Open()
myIns1.ExecuteNonQuery()
End Sub
© Stack Overflow or respective owner