I am studying the WROX
vb.net 2003 book to learn how to save data to an sql database. On page 532-533 it discusses using the objCommand.Paramters.Add command to save data to the SQL database. I thought I had already delared my variables but it is hanging up on the @variables. Do I have to delcare each of these as variables also?????
Here is the error message
Line 1:Incorrect Syntax near '('.
Must delcare the variable
Here is my code. '@readingElaobj'.
Must delare the variable '@admDate'.
Try
'Write ELA Objective Info record
Dim objConnection As SqlConnection = New SqlConnection("server=(local);database=FBISD-TAKS;user id=sa;password=pa55word")
Dim objCommand As SqlCommand = New SqlCommand
objCommand.Connection = objConnection
Dim r4 As Int32
For r4 = 1 To 51
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
"VALUES(@admDate,@studentId,@teacherId,@readingEla obj(r4),@readingElaItemCorrectRespArray(r4),@readi ngElaStudentRespArray(r4))"
objCommand.Parameters.Add("@admDate", admDate)
objCommand.Parameters.Add("@studentId", studentId)
objCommand.Parameters.Add("@teacherId", teacherId)
objCommand.Parameters.Add("@readingElaobj(r4)", readingElaobj(r4))
objCommand.Parameters.Add("@readingElaItemCorrectR espArray(r4)", readingElaItemCorrectRespArray(r4))
objCommand.Parameters.Add("@readingElaStudentRespA rray(r4)", readingElaStudentRespArray(r4))
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try