[thelist] Oops! Parameters in ASP.Net

Chris Anderson Chris at activeide.com
Tue Oct 30 19:30:34 CDT 2007


> I have a problem with the following code. It works if I hard code the
> numbers 3 and 3 but not if I use params. I get the following error:
> Exception Details: System.Data.SqlClient.SqlException: The
> parameterized query '(@MainID int, at Num1 int)INSERT into RecordsDaily (
> RecordsID_rec,' expects the parameter '@MainID', which was not
> supplied.
> I know that this is a common problem and there are about 10,000 of you
> who can answer it.
> 
> TIA,
> Ken
> 
> Dim Num1 As Integer
> Num1 = 3
> Dim MainID As Integer
> MainID = 3
> 
> ' Initialize connection
> conn = New SqlConnection("Server=localhost\SqlExpress;" & _
> "Database=ROADS;Integrated Security=True")
> conn.Open()
> 
> ' Create, execute command
> comm = New SqlCommand("INSERT into RecordsDaily (
> RecordsID_rec,BookingDay_rec) values ( @MainID, @Num1)", conn)
> comm.Parameters.Add("@MainID", Data.SqlDbType.Int)
> comm.Parameters.Add("@Num1", Data.SqlDbType.Int)
> comm.ExecuteNonQuery()

Where are you setting the actual values of the parameters?
You set the command, associate the Parameter objects giving them a name
and type - but no value

Chris



More information about the thelist mailing list