窗体中的登陆按钮:[CODE]
Private Sub btn_Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Submit.Click
Dim userName As String
Dim mycon As New ConnClass() '实例化类
Dim pass As String
userName = Me.txt_UserName.Text.Trim().Replace("'", "_") '用户名
pass = Me.txt_PassWord.Text.Trim().Replace("'", "_") '密码
Dim SqlStr = "select id from tbUser where uid='" & userName & "' and pwd='" & pass & "'"
Dim ds As New DataSet
ds = mycon.myDataSet(SqlStr) '执行SQL语句,并返回DataSet
If ds.Tables.Item(0).Rows.Count > 0 Then '如果输入的登陆信息正确
Dim nMain As New MainRun()
Me.Hide()
nMain.ShowDialog()
Else
MessageBox.Show("服务器拒绝了你的登陆信息,请重新输入!", "系统提示:")
Me.txt_UserName.Text = ""
Me.txt_PassWord.Text = ""
Me.txt_UserName.Focus()
End If
End Sub[/CODE]
类:
[CODE]Public Class ConnClass
Public Function myDataSet(ByVal SqlStr As String) As DataSet
Dim myconn As New System.Data.SqlClient.SqlConnection("server=.;database=myTest;uid=sa;pwd=;")
Dim da As New System.Data.SqlClient.SqlDataAdapter(SqlStr, myconn)
Dim ds As New DataSet
da.Fill(ds)
Return ds
End Function
End Class[/CODE]
[此贴子已经被作者于2006-11-26 16:00:37编辑过]