登陆按钮:
[CODE] Private Sub btn_Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Submit.Click
Dim mycon As New ConnClass()
Dim userName As String
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)
If ds.Tables.Item(0).Rows.Count > 0 Then
Dim nMain As New MainRun()
nMain.Main(userName)
Me.Hide()
nMain.ShowDialog()
Else
MessageBox.Show("Login Failure ")
Me.txt_UserName.Text = ""
Me.txt_PassWord.Text = ""
Me.txt_UserName.Focus()
End If
End Sub[/CODE]
ConnClass 类:[CODE]Public Class ConnClass
Public Function myDataSet(ByVal SqlStr As String) As DataSet
Dim myconn As New System.Data.SqlClient.SqlConnection("server=.;database=test;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]