[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Declaring @variables in SQL connection string

Posted on 2004-09-03
3
Medium Priority
?
192 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

868 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