vb 实现sqldatareader的应用

View Code
 1  Public Sub connect()
2 Dim pass As Boolean
3 pass = False
4 Dim conn As New SqlConnection
5 Dim rs As New SqlCommand
6 Dim dataread As SqlDataReader
7 Dim constr As String
8 'Dim i As Integer
9 Dim sql As String
10 constr = "server=PC-201105311336\SQLEXPRESS;Uid=sa;Pwd=123456;Database=jiaxiaoai" '无源连接
11 conn = New SqlConnection(constr)
12 conn.Open()
13 sql = "select * from sysname"
14 rs = New SqlCommand(sql, conn)
15 dataread = rs.ExecuteReader()
16
17 While (dataread.Read)
18 If dataread(0).ToString = usertext.Text And dataread(1).ToString = passwordtext.Text Then
19 pass = True
20 End If
21 End While
22
23 If pass = True Then
24 Me.Hide()
25 显示学生信息.Show()
26 Else
27 MsgBox("用户名或密码错误")
28 End If
29
30 End Sub

posted @ 2011-08-04 12:17  爱测试的猫咪  阅读(895)  评论(0编辑  收藏  举报