★★关于同时想两个表中插入不同数据的问题。。。。.net+SQL
以下是源代码,主要是向两个表中插入不同的数据。请教各位了。。。
sub insert(sender As Object, e As System.Web.UI.ImageClickEventArgs)
if Session("userid") = "" then
Response.Redirect("login.aspx")
else
dim conn as new sqlconnection( "server=(local);database=desa;uid=sa;pwd=;" )
dim idshow as string
idshow=session("userid")
Dim s As String
Dim i As Int32
For i = 0 To c1.Items.Count - 1
If c1.Items(i).Selected Then
' List the selected items
s = s & ";" & c1.Items(i).Text
s = s & "<br>"
End If
Next
Dim s1 As String
Dim i1 As Int32
For i1 = 0 To c2.Items.Count - 1
If c2.Items(i1).Selected Then
' List the selected items
s1 = s1 & ";" & c2.Items(i1).Text
s1 = s1 & "<br>"
End If
Next
Dim s2 As String
Dim i2 As Int32
For i2 = 0 To c3.Items.Count - 1
If c3.Items(i2).Selected Then
' List the selected items
s2 = s2 & ";" & c3.Items(i2).Text
s2 = s2 & "<br>"
End If
Next
Dim s3 As String
Dim i3 As Int32
For i3 = 0 To c4.Items.Count - 1
If c4.Items(i3).Selected Then
' List the selected items
s3 = s3 & ";" & c4.Items(i3).Text
s3 = s3 & "<br>"
End If
Next
dim strsql as string
dim strsql2 as string
strsql = "insert into com_info (id,c_1,c_2,c_3,c_4) values('"+s+"','"+s1+"''"+s2+"''"+s3+"')"
strsql2 = "insert into rohs_app (no1,no1,no3) values('1','2','3')"
dim cmd as new sqlcommand(strsql,conn)
dim cmd2 as new sqlcommand(strsql2,conn)
Dim dr,dr2 As SqlDataReader
conn.open()
dr = cmd.ExecuteReader
dr2 = cmd2.ExecuteReader
end if
end sub
运行后出现以下情况:
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: ')' 附近有语法错误。
源错误:
行 152:Dim dr,dr2 As SqlDataReader
行 153:conn.open()
行 154:dr = cmd.ExecuteReader
行 155:dr2 = cmd2.ExecuteReader
有没有更好更简单的办法呢,我刚接触这些不久,请说得详细些,谢谢了!!!