kwh3856
asked on
Declaring @variables in SQL connection string
When I try to write a record in the sql database, it tells me that I must declare the @variables eventhough the actual variable has been declared. Am I doing something wrong????? I thought it was supposed to substitue the actual value by using the @ sign??????
Here is what I have
Dim admDate As String..........I dimed all the other variables also just not the @variables
For r4 = 1 To 51
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
"VALUES(@admDate, @studentId, @teacherId, @readingElaobj(r4), @readingElaItemCorrectResp Array(r4), @readingElaStudentRespArra y(r4))"
objConnection.Open()
objCommand.ExecuteNonQuery ()
objConnection.Close()
Next
Thanks
Kenny
Here is what I have
Dim admDate As String..........I dimed all the other variables also just not the @variables
For r4 = 1 To 51
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
"VALUES(@admDate, @studentId, @teacherId, @readingElaobj(r4), @readingElaItemCorrectResp
objConnection.Open()
objCommand.ExecuteNonQuery
objConnection.Close()
Next
Thanks
Kenny
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't think you can do this actually...you need to split out your string...the values from your code cannot be in the "" of the main string...you have to concatenate the values together....note single quotes needed for strings...I am assuming your Arrays and IDs are numeric...if not you will have to add in the single quotes.
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
"VALUES( '" & admDate & "'," & studentId & "," & teacherId "," & readingElaobj(r4) & "," & readingElaItemCorrectRespA rray(r4) & "," & readingElaStudentRespArray (r4) & ")"
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
"VALUES( '" & admDate & "'," & studentId & "," & teacherId "," & readingElaobj(r4) & "," & readingElaItemCorrectRespA
ASKER
Kenny