下面代码运行时,在cmd.ExecuteNonQuery() 代码报错 “ ',' 附近有语法错误”,怎么回事啊?求教高手
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesBu...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmnstringas As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=G:\VB\光盘\光盘文件\data\csglxt_Data.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim cnn As New SqlConnection(cmnstringas)
Dim cmdstring As String
cmdstring = "insert into 用户 values(@姓名,@密码)"
Dim cmd As New SqlCommand(cmdstring, cnn)
cmd.Parameters.AddWithValue("@姓名", TextBox1.Text)
cmd.Parameters.AddWithValue("@密码", TextBox2.Text)
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("输入不完整,请填写完整", "提示信息")
Else
If MessageBox.Show("确定要添加此用户吗?", "提示信息", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cnn.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("添加完毕。")
cnn.Close()
End If
End If
End Sub 展开
Dim cmnstringas As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=G:\VB\光盘\光盘文件\data\csglxt_Data.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim cnn As New SqlConnection(cmnstringas)
Dim cmdstring As String
cmdstring = "insert into 用户 values(@姓名,@密码)"
Dim cmd As New SqlCommand(cmdstring, cnn)
cmd.Parameters.AddWithValue("@姓名", TextBox1.Text)
cmd.Parameters.AddWithValue("@密码", TextBox2.Text)
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("输入不完整,请填写完整", "提示信息")
Else
If MessageBox.Show("确定要添加此用户吗?", "提示信息", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cnn.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("添加完毕。")
cnn.Close()
End If
End If
End Sub 展开
展开全部
OleDbCommand cmd = new OleDbCommand(sql, conn);
int n = (int)cmd.ExecuteScalar();
OleDbCommand cmd1 = new OleDbCommand("insert into AccountTable (date,earning,eatery,life,capture,bleeding,borrow,loan,remark) values (@date,@earning,@eatery,@life,@capture,@bleeding,@borrow,@loan,@remark)";
, conn);
cmd1.ExecuteNonQuery();
应该是这样写吧。。一个cmd怎么能有2个SQL语句呢。。如果想在button1下做2个事情要写2个cmd与cmd1来区分下
int n = (int)cmd.ExecuteScalar();
OleDbCommand cmd1 = new OleDbCommand("insert into AccountTable (date,earning,eatery,life,capture,bleeding,borrow,loan,remark) values (@date,@earning,@eatery,@life,@capture,@bleeding,@borrow,@loan,@remark)";
, conn);
cmd1.ExecuteNonQuery();
应该是这样写吧。。一个cmd怎么能有2个SQL语句呢。。如果想在button1下做2个事情要写2个cmd与cmd1来区分下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询