请教vb6调用自己生成的activedll的方法
写了一个程序,其中在数据库操作时调用一个类clsDB,代码如下:
Public dbConn As New ADODB.Connection
Public dbStatus As Boolean
Public ConnectionString As String
Public Function openDB() As Boolean
On Error GoTo Handle
dbConn.Open ConnectionString
openDB = True
dbStatus = True
Exit Function
Handle:
MsgBox Err.Description & " at clsdb.openDB", vbOKOnly, "出错啦!"
openDB = False
End Function
Public Function closeDB() As Integer
dbConn.Close
dbStatus = False
End Function
Public Function exeSql(sqlstr As String, queryResult As ADODB.Recordset)
On Error GoTo Handle
If dbConn.State = 0 Then
dbConn.Open ConnectionString
End If
Set queryResult = New ADODB.Recordset
Set queryResult.ActiveConnection = dbConn
queryResult.Source = sqlstr
queryResult.CursorLocation = adUseClient
queryResult.LockType = adLockOptimistic
queryResult.CursorType = adOpenDynamic
queryResult.Open
exeSql = queryResult.State
Exit Function
Handle:
exeSql = False
MsgBox Err.Description & " at clsdb.exesql"
End Function
这样操作数据库的时候就用如下代码
Dim db As New clsDb
Dim rs As Recordset
db.openDB
a = db.exeSql("select * from 提醒 ", rs)
我的问题是如果把上面那个数据库操作类编译成activedll(名字是dboperate)的调用方法
我上网查了一下,可以这样,不用引用dll
Private Sub Command1_Click()
Dim rs As Recordset
Set db = CreateObject("dboperate.class1")
db.ConnectionString = "Provider=SQLOLEDB.1;Password=1234567;Persist Security Info=True;User ID=sa;Initial Catalog=成本核算;Data Source=caiwu11\FINANCE;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=caiwu11;Use Encryption for Data=False;Tag with column collation when possible=False"
db.openDB
a = db.exeSql("select * from 生产通知单", rs)
MsgBox rs.Fields(1).Value
MsgBox a
End Sub
但是我的本意是希望能像微软的那些dll一样,先引用,再用如下代码实现
dim db as new dboperate
db.open
请问应该怎么做?
现在我添加引用后在执行到 dim db as new dboperate 时提示错误:缺少用户定义类型,不是工程。
不知哪位高手知道,请指点,谢谢。
[解决办法]
创建一个dll工程,将你希望的类的instacing值设置为5,指定你的项目名称(引用时可以帮助识别,工程属性中设置)添加你的类服务代码,编译成dll
在界面项目中,添加引用,引用你创建的dll项目,剩下的你懂
[解决办法]
dim db as new dboperate.Class1 '<- 应该是类名而不是工程名
[解决办法]
Set db = CreateObject("dboperate.clsdb")
或是
dim db as new dboperate.clsDb