提问:datacombo控件的数据库连接问题!

hy11000 2004-01-07 06:55:59
"源程序"


Private Sub DataCombo1_GotFocus()

VarServer = Text1.Text '服务器名称

VarUser = Text2.Text '登陆标识

VarPassword = Text3.Text 'pass

strconnect = "provider=SQLOLEDB.1;" + "Persist security Info=false;" + "User id=" & VarUser & ";" + "Initial Catalog=master;" + "Data Source=" & VarServer & ";"

Adodc2.ConnectionString = strconnect

If ConnectDbase() Then
MsgBox (strconnect)
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = "select name from sysdatabases"
DataCombo1.Refresh "问题在就在这里!!

Exit Sub

Else

myexit = MsgBox("无法连接网络或者打开数据库!请检查网络设置!", vbOKOnly, "错误提示:")
End
End If

ErrHand:

myexit = MsgBox("错误程序:" & Err.Source & Chr(10) & "错误代码:" & Err.Number & Chr(10) & "错误信息:" & Err.Description, vbAbortRetryIgnore, "错误提示:")

If myexit = 3 Then

Err.Clear

Unload Me

Else

If myexit = 4 Then

Err.Clear

Resume

Else

Err.Clear

Resume Next

End If

End If


End Sub


'========模块:=======================
Public cndbase As New ADODB.Connection

Public VarServer As String '服务名称

Public VarDbase As String '数据库名称

Public VarUser As String '用户名称

Public VarPassword As String '用户口令

Public strconnect As String



'自定义连接数据库函数

Public Function ConnectDbase() As Boolean

On Error GoTo ErrHandle

cndbase.ConnectionString = strconnect

cndbase.Open

cndbase.CursorLocation = adUseServer

ConnectDbase = True

Exit Function

ErrHandle:

ConnectDbase = False

End Function


正常情况应该是,DataCombo1属性设置好,它应该显示SQL中所有的数据库
问题就在现在不管怎么调试,就是显示为空值!

同样的情况,本人在窗体上加个datagrid控件,显示结果就是SQL中所有的数据库
一切正常。

想了老长时间,急求解决办法!





...全文
60 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hy11000 2004-01-07
  • 打赏
  • 举报
回复
问题已解决
少了一行
Adodc2.Refresh
hy11000 2004-01-07
  • 打赏
  • 举报
回复
在线等待中!

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧