VB.NET中执行到这句cmd.ExecuteNonQuery()后老是显示至少有一个参数值没有被指定怎么办呀?
Conn=NewOleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"&"DataSource=e:\invoicing....
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=e:\invoicing.mdb")
Conn.Open()
Dim cmd As OleDbCommand
Dim row As Integer
Dim insertcmd1 As String = "select * from USERS where user-name=TextBox1.Text and pass=TextBox2.Text"
cmd = New OleDbCommand(insertcmd1, Conn)
row = cmd.ExecuteNonQuery()
If row > 0 Then
Form2.Show()
Else
MsgBox("请输入正确的用户名和密码!")
End If
///这是进行用户名和密码匹配的代码,哪位高手能指点指点呀!!! 展开
Conn.Open()
Dim cmd As OleDbCommand
Dim row As Integer
Dim insertcmd1 As String = "select * from USERS where user-name=TextBox1.Text and pass=TextBox2.Text"
cmd = New OleDbCommand(insertcmd1, Conn)
row = cmd.ExecuteNonQuery()
If row > 0 Then
Form2.Show()
Else
MsgBox("请输入正确的用户名和密码!")
End If
///这是进行用户名和密码匹配的代码,哪位高手能指点指点呀!!! 展开
2个回答
展开全部
Dim insertcmd1 As String = "select * from USERS where user-name=TextBox1.Text and pass=TextBox2.Text"
应该写成
Dim insertcmd1 As String = "select * from USERS where user-name='" & TextBox1.Text & "' and pass='" & TextBox2.Text & "'" '注意引号
这是最简单的改法,只是有个问题,你的文本框内输入的内容不能有引号,否则报错。
下面还有一种改法,不知你能否理解。
Conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=e:\invoicing.mdb")
Conn.Open()
Dim cmd As OleDbCommand
Dim row As Integer
Dim insertcmd1 As String = "select * from USERS where user-name=? and pass=?"
cmd.Parameters.AddWithValue("?", TextBox1.Text)
cmd.Parameters.AddWithValue("?", TextBox2.Text)
cmd = New OleDbCommand(insertcmd1, Conn)
row = cmd.ExecuteNonQuery()
If row > 0 Then
Form2.Show()
Else
MsgBox("请输入正确的用户名和密码!")
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询