Solved

Declaring @variables in SQL connection string

Posted on 2004-09-03
3
187 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:kwh3856
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
natloz earned 500 total points
ID: 11976918
objCommand.CommandText = "Insert Into itemAnalysisDetail " & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
                                "VALUES(admDate, studentId, teacherId, readingElaobj(r4), readingElaItemCorrectRespArray(r4), readingElaStudentRespArray(r4))"

--Remove all the @ symbols since you are not using a Stored procedure.
0
 

Author Comment

by:kwh3856
ID: 11976957
Thanks a bunch!!!!!

Kenny
0
 
LVL 7

Expert Comment

by:natloz
ID: 11976964
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) & ")"
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Iteration Help (Asp.net VB) 5 25
VB.NET String Settings and Temp Folder Question 3 57
Open a link in vb.net 2 16
Access/Visual Basic Question 3 29
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question