我想用不同的用户启动程序,但我的代码不起作用
Private Sub Btn_login_Click(sender As Object,e As EventArgs)句柄 Btn_login.Click
konek()
cmd = New SqlCommand("select User_id, Username, Password from [dbo].[User] where Username = '" & Txtusername.Text & "' and Password ='" & Txtpassword.Text & "'", conn)
baca = cmd.ExecuteReader()
baca.Read()
If baca.HasRows Then
baca.Close()
cmd = New SqlCommand("insert into [Login].[dbo].[Login_log] (User_id,Date_jam_in,Pc_short,ip) VALUES ('" & Txtusername.Text & "','" & DateAndTime.Now & "','" & Txtnamakom.Text & "','" & TxtIPAddress.Text & "')", conn)
baca = cmd.ExecuteReader()
MsgBox("Login Berhasil", MsgBoxStyle.OkOnly, "Sucses")
Process.Start("cmd.exe" + Txtusername.Text + "Notepad.exe" + Txtpassword.Text)
Else
MsgBox("Sorry, username or password ora ene", MsgBoxStyle.OkOnly, "Invalid")
End If
Txtpassword.Text = ""
Txtusername.Text = ""
Txtusername.Focus()
End Sub
答案 0 :(得分:0)
关闭你的READER然后再读一遍你的另一个查询,然后在过程结束时再关闭READER('baca'是你的读者)
Private Sub Btn_login_Click(sender As Object, e As EventArgs) Handles Btn_login.Click
konek()
cmd = New SqlCommand("SELECT User_id, Username, Password from [dbo].[User] WHERE Username = '" & Txtusername.Text & "' and Password ='" & Txtpassword.Text & "'", conn)
baca = cmd.ExecuteReader()
baca.Read()
If baca.HasRows Then
baca.Close()
cmd = New SqlCommand("insert into [Login].[dbo].[Login_log] (User_id,Date_jam_in,Pc_short,ip) VALUES ('" & Txtusername.Text & "','" & DateAndTime.Now & "','" & Txtnamakom.Text & "','" & TxtIPAddress.Text & "')", conn)
baca = cmd.ExecuteReader()
baca.read()
MsgBox("Login Berhasil", MsgBoxStyle.OkOnly, "Sucses")
Process.Start("cmd.exe" + Txtusername.Text + "Notepad.exe" + Txtpassword.Text)
baca.close()
Else
MsgBox("Sorry, username or password ora ene", MsgBoxStyle.OkOnly, "Invalid")
End If
Txtpassword.Text = ""
Txtusername.Text = ""
Txtusername.Focus()
End Sub