ExecuteSQL要定义吗

hillwayqiang 2004-10-03 03:47:20
编译提示
子程序或函数未定义
...全文
288 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
laviewpbt 2004-10-03
  • 打赏
  • 举报
回复
connectstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=K:\招聘单位信息管理系统\zpdw.mdb;Persist Security Info=False;Jet OLEDB:database Password=1234"
hillwayqiang 2004-10-03
  • 打赏
  • 举报
回复
Public Function connectstring() As String
connectstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\incubus.mdb;Persist Security Info=False;Jet OLEDB:database Password=1234"
End Function


我用access直接建的数据库,名字为:zpdw.mdb,放在K:\招聘单位信息管理系统 文件夹下
connectstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\incubus.mdb;Persist Security Info=False;Jet OLEDB:database Password=1234"

要怎样写(改)啊。
hillwayqiang 2004-10-03
  • 打赏
  • 举报
回复
Private Sub CmdSearch2_Click()
Dim txtSQL As String
Dim MsgText As String
Dim dd(4) As Boolean
Dim mrc As ADODB.Recordset

txtSQL = "select * from zpdw where "
If Check1.Value Then
If Trim(CbErea.Text) = "" Then
sMeg = "请选择地区!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
CbErea.SetFocus
Exit Sub
Else

dd(0) = True
txtSQL = txtSQL & "地区 = '" & Trim(CbErea.Text) & "'"
End If
End If

If Check2.Value Then
If Trim(CmdSearch.Text) = "" Then
sMeg = "请选择单位性质!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
CmdSearch.SetFocus
Exit Sub
Else
dd(1) = True
If dd(0) Then
txtSQL = txtSQL & "and 单位性质 = '" & CmdSearch.Text & "'"
Else
txtSQL = txtSQL & "单位性质 = '" & CmdSearch.Text & "'"
End If
End If
End If

If Check3.Value Then
If Trim(Cbattend.Text) = "" Then
sMeg = "请选择是否参加过我院大型招聘会!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Cbattend.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Then
txtSQL = txtSQL & "and 参加过 = '" & Cbattend.Text & "'"
Else
txtSQL = txtSQL & "参加过 = '" & Cbattend.Text & "'"
End If
End If
End If

If Check4.Value Then
If Trim(Cbreceive.Text) = "" Then
sMeg = "请选择是否招过我院毕业生!"
MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
Cbreceive.SetFocus
Exit Sub
Else
dd(2) = True
If dd(0) Or dd(1) Or dd(2) Then
txtSQL = txtSQL & "and 招过 = '" & Cbreceive.Text & "'"
Else
txtSQL = txtSQL & "招过 = '" & Cbreceive.Text & "'"
End If
End If
End If

If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then
MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If

txtSQL = txtSQL & " order by 单位名称 "
Set mrc = ExecuteSQL(txtSQL, MsgText)

With myflexgrid
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 0) = "单位名称"
.TextMatrix(1, 1) = "地区"
.TextMatrix(1, 2) = "单位性质"
.TextMatrix(1, 3) = "参加过"
.TextMatrix(1, 4) = "招过"
.TextMatrix(1, 5) = "招聘人数"
.TextMatrix(1, 6) = "招聘日期"
.TextMatrix(1, 7) = "通讯地址"
.TextMatrix(1, 8) = "邮编"
.TextMatrix(1, 9) = "联系人"
.TextMatrix(1, 10) = "联系电话"
.TextMatrix(1, 11) = "传真电话"
.TextMatrix(1, 12) = "网址"
.TextMatrix(1, 13) = "电子邮箱"
.TextMatrix(1, 14) = "备注"



Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
.TextMatrix(.Rows - 1, 6) = Format(mrc.Fields(6), "yyyy-mm-dd")
.TextMatrix(.Rows - 1, 7) = mrc.Fields(7)
.TextMatrix(.Rows - 1, 8) = mrc.Fields(8)
.TextMatrix(.Rows - 1, 9) = mrc.Fields(9)
.TextMatrix(.Rows - 1, 10) = mrc.Fields(10)
.TextMatrix(.Rows - 1, 11) = mrc.Fields(11)
.TextMatrix(.Rows - 1, 12) = mrc.Fields(12)
.TextMatrix(.Rows - 1, 13) = mrc.Fields(13)
.TextMatrix(.Rows - 1, 14) = mrc.Fields(14)
mrc.MoveNext
Loop

End With

mrc.Close
End Sub
laviewpbt 2004-10-03
  • 打赏
  • 举报
回复
这是一个连接数据库的函数,代码如下
Public Function executesql(ByVal sql As String, mstring As String) As ADODB.Recordset
Dim cnn As New Connection
Dim rst As ADODB.Recordset
Dim stoken() As String
On Error GoTo Executesql_error
stoken = Split(sql)
Set cnn = New ADODB.Connection
cnn.Open connectstring
If InStr("INSERT,DELETE,UPDATE", UCase$(stoken(0))) Then
cnn.Execute sql
mstring = stoken(0) & "query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(sql), cnn, adOpenKeyset, adLockOptimistic
Set executesql = rst
mstring = "查询到" & rst.RecordCount & "条记录"
End If
executesql_exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
Executesql_error:
mstring = "查询错误:" & Err.Description
Resume executesql_exit
End Function
Public Function connectstring() As String
connectstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\incubus.mdb;Persist Security Info=False;Jet OLEDB:database Password=1234"
End Function
把他们添加到模块中
当然Data Source=" & App.Path & "\incubus.mdb要该为你自己的数据库的路径

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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