我的问题是:
我在Access数据库中添加新用户。
如果已输入tabNum的用户已存在 - 您将看到messagebox。
但我在代码中出错:
此代码始终显示消息Record with this TabNum already exists!
,K的值始终等于1.
你能帮我找到我的代码中的错误吗?
Dim k As Integer = 0
Dim Con2 As New OleDb.OleDbConnection("Provider=Microsoft.ACE.oledb.12.0; Data source=" + bpath)
Dim SqlCom2 As OleDb.OleDbCommand
SqlCom2 = New OleDb.OleDbCommand("SELECT COUNT(*) FROM [Users] WHERE [TabNum] = @T1", Con2)
SqlCom2.Parameters.Add("@T1", OleDbType.WChar).Value = usadm.DataGridView1.CurrentRow.Cells(0).Value
Con2.Open()
SqlCom2.ExecuteNonQuery()
k = SqlCom2.ExecuteScalar()
If k > 0 Then
MsgBox("Record with this TabNum already exists!")