在DLL中如何建立数据库的链接及如何进行操作

bingbhz 2002-07-29 01:45:51
在ASP页面中调用组件,数据库链接语句通过参数传入DLL中,在DLL中建立数据库链接,并进行数据库操作,如添加、查找、删除、修改等

最好来段代码
...全文
12 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
希偌 2002-07-29

sub main()
中定义需要在数据库操作中用到的变量
调用的时候用
.dll实例.属性来个这些变量赋值,最后调用过程来完成操作或调用函数来返回数据集
回复
zyhowe 2002-07-29
Function GetRs(ByVal connstr As String, ByVal FieldStr As String, ByVal TableStr As String, ByVal wherestr As String, ByVal orderstr As String, ByVal sortstr As String) As Object

Dim conn As New ADODB.Connection
Dim GetRs1 As New ADODB.Recordset
Dim sql As String

On Error GoTo errhandler
conn.Open connstr
If FieldStr = "" Then FieldStr = "*"
sql = "select " & FieldStr & " from " & TableStr

If wherestr <> "" Then
sql = sql & " where " & wherestr
End If

If orderstr <> "" Then
If sortstr <> "desc" Then sortstr = "asc"
sql = sql & "order by " & orderstr & sortstr
End If

GetRs1.Open sql, conn, 1, 3
Set GetRs = GetRs1
Exit Function
errhandler:
MsgBox Err.Description
End Function
以上为组件haha.xixi

以下为调用



Private Sub Command1_Click()
Dim connstr As String
connstr = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Pwd=aaa;Initial Catalog=bbb;Data Source=ccc;Locale Identifier=2052;Connect Timeout=15;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"
Dim rs As Object
Dim TestObject As Object
Set TestObject = CreateObject("haha.xixi")
Set rs = TestObject.GetRs(connstr, "", "TblMembership", "", "", "")
MsgBox rs.RecordCount
rs.close
set rs=nothing
set TestObject=nothing
End Sub
回复
lanying 2002-07-29
这很简单呀,跟asp中没有什么区别
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告