新人一个,请求帮忙,有关链接数据库的问题。
Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = "server=DELL PC;uid=sa;pwd=sql;database=gg_user "
conn.Open()
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = conn
= "select * from login where user_id='" & Me.txtuser_id.Text & "' and user_pwd=" & Me.txtpassword.Text & " "
Dim dr As SqlClient.SqlDataReader
dr = cmd.ExecuteReader
If dr.Read Then
If dr!user_state = "停用" Then
MsgBox("用户已停用!!!")
End If
If txtuser_id.Text = dr.Item("user_id") And txtpassword.Text = dr.Item("user_pwd") Then
MsgBox("登陆成功!")
Me.Hide()
Dim form2 As New Form2
form2.Show()
End If
Else
MsgBox("请输入正确的用户名和密码或用户不存在!!", MsgBoxStyle.Critical)
End If
dr.Close()
conn.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtuser_id.KeyPress
If e.KeyChar = Chr(13) Then
txtpassword.Focus()
txtpassword.SelectAll()
End If
End Sub
Private Sub txtpassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtpassword.KeyPress
If e.KeyChar = Chr(13) Then
Button1.Focus()
End If
End Sub
End Class