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

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

最好来段代码
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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中没有什么区别

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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