#2
不懂才问2018-02-22 16:45
|
Imports System.Data.SqlClient
Public Class Form1
Dim conn As New SqlConnection()
Dim cmd As New SqlCommand
Dim datard As SqlDataReader
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim constr As String '连接数据源
constr = "user id=sa;password=123456;initial catalog=rsgl;data source=(local)"
conn.ConnectionString = constr
conn.Open()
cmd.Connection = conn '命令对像连接
= CommandType.Text
Dim cmdstr As String '定义连接查询语句
cmdstr = "select * from 用户表 "
= cmdstr
Dim datard As SqlDataReader '定义读取方式
datard = cmd.ExecuteReader
Dim AA As String
AA = datard.Read
If datard.Item(CInt("psw")) = TextBox1.Text Then
'TextBox1.Text = datard.GetString(1)
TextBox2.Text = datard.GetString(2)
datard.Close()
conn.Close()
Else
MsgBox("输入不正确")
End If