求vb.net2005登录sql2000程序
求代码
想做一个vb.net2005登录SQL2000窗体,两个TEXTBOX控件输入用户名密码,连接数据库成功MESSAGEBOX("ok")否则重新输入
[解决办法]
"data source=(local);inital catalot=mydb;uid="+textBox1.Text+";pwd="+textBox2.Text+")";
[解决办法]
随便写了下,你试试
Public Class denglu
Public cmdSqlServer As New SqlClient.SqlCommand
'创建一个SqlCommand对象,用于实例化drSqlServer
Private Sub RegLabClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles RegLab.LinkClicked
registration.Show()
End Sub
Dim MyConnection As String = "server=(local);database=数据库名称;uid=sa;pwd="
'连接本地数据库,数据库的名称,登陆数据库时用户名和密码'
Dim Mycn As New SqlConnection(MyConnection)
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Try
Mycn.Open() '打开数据库'
Dim sql As String = "Select count(*) from Users where User_Name='" + TxtName.Text.Trim() + "' and User_Pwd='" + TxtPwd.Text.Trim() + "'"
'sql中统计匹配的数目,count(*)统计全部数据,TxtName是用户名的textbox,TxtPwd密码的
Dim i As Integer
Dim com As New SqlCommand(sql, Mycn)
Dim DR As SqlDataReader = com.ExecuteReader() '检索数据库中的用户
While DR.Read()
i = DR.GetInt32(0)
End While
DR.Close() '关闭阅读器
If i = 0 Then
MessageBox.Show("请输入正确的帐号和密码!")
Else
form2.Show()‘打开下个窗体
End If
Catch ex As Exception
MessageBox.Show("btnOK_Click,bz = 0出错!" + ex.Message(), "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
Finally
Mycn.Close() '关闭数据库'
End Try
End Sub
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
Me.Close()’退出按钮
End Sub
End Class