Hi
I am using ASP.Net 2.0 code behind VB and SQL Server 2000. My problem is I want to insert multiple rows in one click. When I am trying to insert it will give me error like The name CQ is not permitted in this context.... My code is
Dim CQ As String = Request("CommentsAfterQuestion")
Dim CID As Integer = Request("drpDLforCentreName")
Dim q12 As Integer = Request("q12")
Dim q13 As Integer = Request("q13")
Dim CD As String = Request("txtCallDate ")
Dim strCon As New SqlConnection("Data Source=d; Initial Catalog=NSQL; Integrated Security=True;")
Dim strCMD As New SqlCommand
strCon.Open()
Dim strSQL As String = ""
strSQL = "Insert into QuestionDetails (SurveyTypeID, CommentsAfterQuestion, CentreID, CentreScore, EnquiryDate, QCat) " & _
"Values (1, CQ, CID, q12, CD, 6), " & _
"(1, CQ, CID, q13, CD, 7)"
Try
strCMD = New SqlCommand(strSQL, strCon)
strCMD.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
Please anyone help me how can I insert multiple rows.
Thanks in advance
Insert into QuestionDetails (SurveyTypeID, CommentsAfterQuestion, CentreID, CentreScore, EnquiryDate, QCat)
select 1, 'comments', 401, 8, '12/05/2009', 6
union all
select 1, 'comments', 401,8, '12/05/2009', 7
In code:
strSQL = "Insert into QuestionDetails (SurveyTypeID, CommentsAfterQuestion, CentreID, CentreScore, EnquiryDate, QCat) " & _
"select 1, '" & CQ & "', " & CID & ", " & q12 & ", '" & CD & "', 6 " & _
" union all select 1, '" & CQ & "', " & CID & "," & q13 & ", '" & CD & "', 7"