首页 | 社区 | 博客 | 招聘 | 文章 | 新闻 | 下载 | 读书 | 代码
亲,您未登录哦! 登录 | 注册

VB与数据连接的心得

打印文章

分享到:
set conn=New ADODB.Connection
set rs=New adodb.recordset
本机名称:jszx3-11
server:jszx3-11
database:wzc
uid=sa
pwd=
driver={sql server}

'定义ADO数据库对象
conn.ConnectionString = "driver={SQL Server};" & _
"server=" & ServerName & ";uid=" & UserName & ";
pwd=" & Password & ";database=" & DatabaseName & ""
'连接数据串

Private Sub Command1_Click(Index As Integer)
Dim m As String
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Driver={SQL Server};server=JSZX3-11;uid=sa;pwd=;database=wzc"
conn.Open
rs.Open "select 用户名,密码 from login where 用户名='" & Trim(Combo1.Text) & "' And 密码='" & Trim(Text1.Text) & "'", conn, adOpenStatic, adLockReadOnly, adCmdText
If rs.EOF = True And rs.BOF Then
m = MsgBox("请重新登录", vbExclamation)
Text1.Text = ""
Text1.SetFocus
Else
Form1.Hide
Form2.Show
End If
rs.Close
End Sub

Private Sub Command2_Click(Index As Integer)
Form2.Show
End Sub

Private Sub Command3_Click()
Unload Form1

End Sub


Private Sub Form_Load()
Dim t As Integer
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "Driver={SQL Server};server=JSZX3-11;uid=sa;pwd=;database=wzc"
conn.Open
rs.Open "select 用户名 from login", conn, adOpenStatic, adLockReadOnly, adCmdText
Dim i As String
For t = 0 To Val(rs.RecordCount) - 1
i = Trim(rs.Fields("用户名").Value)
rs.MoveNext
Combo1.AddItem i
Next t
rs.Close

End Sub

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )

编程爱好者论坛

本栏最新文章