- 分享
- 0
- 人气
- 0
- 主题
- 2
- 帖子
- 269
- UID
- 270819
- 积分
- 188
- 阅读权限
- 13
- 注册时间
- 2009-10-15
- 最后登录
- 2013-9-30
- 在线时间
- 154 小时
|
请问下这个Code的问题在哪里?当我输入 ID,Pass,FirstName都符合Database,但是LasNamet不符合的话它也会成功进入Insert Data的情况然后会出现error因为有些Data重复了.
Dim DBCon As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Kini\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\VB.accdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Staff WHERE StaffID ='" & txtStaffID.Text & "' and Password = '" & txtPass.Text & "' and UserFirstName= '" & txtFN.Text & "' and UserLastName= '" & txtLN.Text & "'", DBCon)
DBCon.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If (sdr.Read() = True) Then
MessageBox.Show("The data entered already exist!", "System Information")
sdr.Close()
DBCon.Close()
ElseIf (sdr.Read() = False) Then
Dim cmd2 As String
Dim DBCon2 As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Kini\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\VB.accdb")
cmd2 = "INSERT INTO Staff Values ( '" & txtStaffID.Text & "', '" & txtPass.Text & "','" & txtFN.Text & "', '" & txtLN.Text & "')"
Dim sdr2 As OleDbCommand
sdr2 = New OleDbCommand(cmd2, DBCon2)
DBCon2.Open()
Dim objcmd As OleDbCommand
objcmd = New OleDbCommand(cmd2, DBCon2)
objcmd.ExecuteNonQuery()
DBCon2.Close()
valid5 = True
End If
End If |
|