VB编写的登录局域网内的sql2000数据库服务器代码

标签: sql数据库服务器vbmicrosoftstringdropdown
3150人阅读 评论(0) 收藏 举报
分类:

'工程引用Microsoft SQLDMO Object Library
'Microsoft ActiveX Data Objects 2.8 Library
'定义一个连接对象..和记录集对象
Public conn As New ADODB.Connection '连接的
Public recv As New ADODB.Recordset '用来接收数据的

Private Sub Nsqlser_DropDown()
     If Nsqlser.ListCount > 0 Then Exit Sub
     Dim Server As SQLDMO.NameList '名字列表namelist
     Dim appDMO As New SQLDMO.Application 'sqldmo应用
     Dim i As Integer
     Set Server = appDMO.ListAvailableSQLServers '得到所有的sql sever 列表
     For i = 1 To Server.Count
     Nsqlser.AddItem Server(i) 'Nsqlser为下拉列表框
     Next
End Sub

Private Sub Command1_Click()
'连接按钮事件click()
Dim sql As String
Dim txtaddres As String
Dim txtuser As String
Dim txtpass As String
Dim msdb As String

txtaddres = Nsqlser.Text
txtuser = Text1.Text
txtpass = Text2.Text
msdb = Text3.Text

sql = "Provider=SQLOLEDB.1;Password=" & txtpass & ";Persist Security Info=True;User ID=" & txtuser & ";Initial Catalog=" & msdb & ";Data Source = " & txtaddres
'sql变量力存放的是连接字符串....
conn.ConnectionString = sql '连接字符串..
conn.open '连接
If conn.State = 0 Then
MsgBox "数据库联接失败"
Else
MsgBox "数据库联接成功"
End If
conn.Close
Set conn = Nothing
End Sub


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1252922次
    • 积分:14803
    • 等级:
    • 排名:第772名
    • 原创:292篇
    • 转载:60篇
    • 译文:2篇
    • 评论:176条
    文章存档
    最新评论
    C#+Jquery
    C#+Jquery