急求高手解决:VB怎样连接数据库
我现在正在做一个VB+SQL SERVER的系统开发,我做到用户登录界面的时候,要用到ADO来做,我已经创建了数据库和相关表的内容。但我在把VB和我所做的数据库连接起来的时候老是出问题,而且在ADODC的属性connectionstring里找不到我创建的数据库。希望帮帮忙解决一下下面是连接数据库的代码,做了一个模块
Public conn As ADODB.Connection
Public mrc As ADODB.Recordset
Public cmd As ADODB.Command
Public user_id As String
Public Sub databaseopen()
Dim connstring As String
Set conn = New ADODB.Connection
connstring = "provider = SQLOLEDB.1;persist security info = false;user id = sa;pwd = 839951;initial catalog = student;data source = (local)"
conn.CursorLocation = adUseClient
conn.Open connstring
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
End Sub
Public Sub databaseclose()
conn.Close
End Sub
系统显示消息:连接字符串属性无效。是不是需要指定数据库的位置啊,data source = (local)"是不是有问题。 --------------------编程问答-------------------- connstring= "Provider=sqloledb;Server=" & ServerIP & ";UID=" & UID & ";PWD=" & PWD & ";database=" & DBName
对应的参数值换成你的数据库的信息 --------------------编程问答-------------------- 是连接字符串有问题 --------------------编程问答--------------------
With conn--------------------编程问答--------------------
If .State = adStateOpen Then .Close
.ConnectionString = "driver=SQL Server;server=计算机名或IP地址;uid=sa;pwd=sa的密码;database=数据库名"
.CommandTimeout = 0
.Open
End With
connstring = "provider = SQLOLEDB.1;persist security info = false;user id = sa;pwd = 839951;initial catalog = 数据库名;data source = 服务器名"
LZ,你用的SQL SERVER2000吧,看一下服务器名。如果不清楚的话,可以添加一个ADODC控件,在它的属性中设置ConnectionString,生成以后,把它此属性的值拷贝过来就是上面你所需要的字符串。也就是借助控件的自动生成功能
补充:VB , 基础类