关于VB数据库访问的问题

doo doo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位高手,我做的程序在我的电脑调试、编译连接数据库一切都正常,放到别人的电脑上再下面的OpenRecoset(rs, strSQL)时候会提示 "承建单位站前ID" 字段无效,我把sql语句改为"select * from AAA where BBB=CCC",那么就会提示 字段 BBB 无效 ,而这一切在我的电脑上都没有错误提示,编译成exe文件到别人的电脑上也会提示这样的错误,我和别人的VB是同一张盘上的,我的2000server系统里也没有装特殊的东西就是打全了所有的系统补丁,装了sql server个人版 office2003 ,,程序连接数据库是sql2000在另外一台电脑上,数据库结构和数据和程序里面的sql语句因该没有错误,因为在我自己电脑上一切操作都正常,谁能告诉我是那方面的原因呀


Private Sub Form_Load()
Dim i As Integer
Dim strSQL As String
Dim rs As New ADODB.Recordset
Dim lngRecoCounts As Long

LblProject.Caption = frmProgressRailwayName
Me.Caption = frmProgressCaption

'
strSQL = "Select * From 正线轨道,承建单位,监理单位 where 正线轨道.名称='" & frmProgressRailwayName & "'" _
& " and 正线轨道.承建单位站前ID=承建单位.ID and 正线轨道.监理单位ID=监理单位.ID"

If frmProgressofRailway = True Then strSQL = "select * from 正线轨道属性" '如果标记为真,统计正线轨道的进度信息


Call OpenRecoset(rs, strSQL)

If GetRecordCount(rs) < 1 Then rs.Close: Exit Sub

With rs
RailwayBeginDate = !计划开工日期
RailwayFinishdate = !计划竣工日期
LenofRailway = !正线铺轨

For i = 0 To .Fields.Count - 1
If Right(.Fields(i).Name, 2) <> "ID" Then
txtInfo = txtInfo & .Fields(i).Name & ":" & .Fields(i).Value & vbCrLf
End If
Next
End With
rs.Close
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
end sub
' 集中打开数据库的记录,以便集中处理连接断开错误
Public Function OpenRecoset(ByRef RecSet As ADODB.Recordset, ByVal strSQL As String, _
Optional ByRef CursorType As ADODB.CursorTypeEnum = adOpenForwardOnly, _
Optional ByRef LockType As ADODB.LockTypeEnum = adLockReadOnly, _
Optional ByVal cmdType As Long = adCmdText) As Boolean

On Error GoTo ErrHandler
Set RecSet.ActiveConnection = GetConnection()
RecSet.CursorLocation = adUseClient
RecSet.CursorType = CursorType
RecSet.LockType = LockType

RecSet.Open strSQL, , , , cmdType
OpenRecoset = True
Exit Function
ErrHandler:
Call ReportError
OpenRecoset = False
End Function
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
doo
智能路由器 684 成员 913 内容