Link to home
Start Free TrialLog in
Avatar of kwh3856
kwh3856Flag for United States of America

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), @readingElaItemCorrectRespArray(r4), @readingElaStudentRespArray(r4))"
                    objConnection.Open()
                    objCommand.ExecuteNonQuery()
                    objConnection.Close()
                Next



Thanks
Kenny
ASKER CERTIFIED SOLUTION
Avatar of natloz
natloz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kwh3856

ASKER

Thanks a bunch!!!!!

Kenny
Avatar of natloz
natloz

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) & "," & readingElaItemCorrectRespArray(r4) & "," & readingElaStudentRespArray(r4) & ")"