关闭

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

3208人阅读 评论(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网站的观点或立场
    个人资料
    • 访问:1209745次
    • 积分:15216
    • 等级:
    • 排名:第768名
    • 原创:294篇
    • 转载:60篇
    • 译文:2篇
    • 评论:188条
    文章存档
    最新评论
    C#+Jquery
    C#+Jquery