'里面写一个方法 连接数据库的字符串 '读取连接字符串 Public Function readCN() As String On Error GoTo Connect_Err Dim strCn As String Dim strDatabase As String Dim strUser As String Dim strCode As String Dim strServer As String' Screen.MousePointer = 11
strDatabase = "Master" strUser = "sa" strCode = "" strServer = "ServerDB" If strDatabase = "" Then GoTo Connect_Err End If
Proc_Exit: Exit FunctionConnect_Err: Screen.MousePointer = 0 Err.Raise 100, "ReadCN", "未设置服务端信息,请用设置工具进行设置!" GoTo Proc_ExitEnd Function''然后写一个方法 执行SQL语句的 '里面有连接数据库 Public Function DoBySql(strsql As String) On Error GoTo Proc_Err Dim strCn As String Dim cn As New ADODB.Connection
private sub DDD() Dim Obj as object Dim strSql as string dim rs as new ADODB.Recordset set obj=Createobject("comDll.class",ServerMTS) strSql="Select * from spt_values"
set rs=obj.dobysql(strsql) if rs.recordset <1 then exit sub end if ................ End'''现在的问题是 因为我的电脑作为开发环境。我会把
Class的属性是 MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 2 'RequiresTransaction
'里面写一个方法 连接数据库的字符串
'读取连接字符串
Public Function readCN() As String
On Error GoTo Connect_Err
Dim strCn As String
Dim strDatabase As String
Dim strUser As String
Dim strCode As String
Dim strServer As String' Screen.MousePointer = 11
strDatabase = "Master"
strUser = "sa"
strCode = ""
strServer = "ServerDB"
If strDatabase = "" Then
GoTo Connect_Err
End If
strCn = "Provider=SQLOLEDB.1;Password=" & strCode & ";Persist Security Info=True;User ID=" & strUser & _
";Initial Catalog=" & strDatabase & ";Data Source=" & strServer
readCN = strCn
' Screen.MousePointer = 0
Proc_Exit: Exit FunctionConnect_Err: Screen.MousePointer = 0
Err.Raise 100, "ReadCN", "未设置服务端信息,请用设置工具进行设置!" GoTo Proc_ExitEnd Function''然后写一个方法 执行SQL语句的
'里面有连接数据库
Public Function DoBySql(strsql As String)
On Error GoTo Proc_Err
Dim strCn As String
Dim cn As New ADODB.Connection
strCn = readCN()
cn.CursorLocation = adUseClient
cn.Open strCn
cn.Execute strsql
Proc_Exit:
Exit Function
Proc_Err:
End Function
把comDll.dll在我的电脑的组件服务添加。
数据库服务器是本公司Lan内服务器。
private sub DDD()
Dim Obj as object
Dim strSql as string
dim rs as new ADODB.Recordset set obj=Createobject("comDll.class",ServerMTS)
strSql="Select * from spt_values"
set rs=obj.dobysql(strsql)
if rs.recordset <1 then
exit sub end if
................ End'''现在的问题是 因为我的电脑作为开发环境。我会把