kwh3856
asked on
Syntax Error using objCommand.Parameters.Add......attempting to write data to sql database
I am trying to write a record to an SQL database. I thought I have correctly delcared my variables but the system is giving a syntax error on the admDate line. It is telling me to define the variable, but I have already defined it. The admDate is actually Dim as a String variable....Would this create my problem?????
Any help is greatly appreciated.
Dim admDate As String
Try
'Write ELA Objective Info record
Dim objConnection As SqlConnection = New SqlConnection("server=(loc al);databa se=FBISD-T AKS;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,@studentI d,@teacher Id,@readin gElaobj(r4 ),@reading ElaItemCor rectRespAr ray(r4),@r eadingElaS tudentResp Array(r4)) "
objCommand.Parameters.Add( "@admDate" , SqlDbType.DateTime, 10) <<<------- Problem Line..I Think!
objCommand.Parameters.Add( "@studentI d", SqlDbType.Int, 4)
objCommand.Parameters.Add( "@teacherI d", SqlDbType.Int, 4)
objCommand.Parameters.Add( "@readingE laobj", SqlDbType.VarChar, 2)
objCommand.Parameters.Add( "@readingE laItemCorr ectRespArr ay", SqlDbType.Int, 4)
objCommand.Parameters.Add( "@readingE laStudentR espArray", SqlDbType.Int, 4)
objConnection.Open()
objCommand.ExecuteNonQuery ()
objConnection.Close()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Thanks
Kenny
Any help is greatly appreciated.
Dim admDate As String
Try
'Write ELA Objective Info record
Dim objConnection As SqlConnection = New SqlConnection("server=(loc
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,@studentI
objCommand.Parameters.Add(
objCommand.Parameters.Add(
objCommand.Parameters.Add(
objCommand.Parameters.Add(
objCommand.Parameters.Add(
objCommand.Parameters.Add(
objConnection.Open()
objCommand.ExecuteNonQuery
objConnection.Close()
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Thanks
Kenny
Date should be Dim as DATETIME
ASKER
I am tring to insert as is.
Thanks
kenny
Thanks
kenny
Dim admDate As DateTime
the problem is ...
"VALUES(@admDate,@studentI d,@teacher Id,@readin gElaobj(r4 ),@reading ElaItemCor rectRespAr ray(r4),@r eadingElaS tudentResp Array(r4)) "
the (r4)s are you trying to access an array there ?
"VALUES(@admDate,@studentI
the (r4)s are you trying to access an array there ?
you are also never setting values to your parameters here.
ASKER
Yes...I am trying to use an array. Is that the right syntax????
Thanks
Kenny
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.
ASKER
I thought I was setting the values to the memory variables I had set previously in the program. Does it not work this way??
Thanks
Kenny
Thanks
Kenny
ASKER
Thank you both for turning on so many lights. I have been trying to understand the syntax and how this works for about 3 to 4 days now. All the tutorials and Wrox books I have read never really made this clear. Let me go make so major changes to my code. Again THANKS FOR YOUR HELP
Thanks
Kenny
Thanks
Kenny
OK Kenny,
If you need any help you could email me at ********************
RC
editted: gregoryyoung removed email address.
If you need any help you could email me at ********************
RC
editted: gregoryyoung removed email address.
ASKER
Once again....THANKS!!!!!!!!!!! !!!
hmm ... didnt I point out what the issue was ?
I agree we should split that point Gregory...
RC
RC
ASKER
Yes.....I wanted to split the points but did not see the button. I will post the question again so you can submit your answer. Again...thank you very much.
Kenny
Kenny
Are you trying to hit a stored procedure? or just trying to run that insert as is?
RC