关于VB数据库访问的问题
各位高手,我做的程序在我的电脑调试、编译连接数据库一切都正常,放到别人的电脑上再下面的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
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
...全文
相关推荐
VB5DB-DLL问题
VB5DB-DLL问题主要涉及到的是Visual Basic 5.0中的数据库访问组件。在VB5中,开发者可以利用VB5DB.DLL这个动态链接库来实现对数据库的连接和操作,比如读取、写入数据等。
vb 压缩和修复access数据库
以下是一个VB代码示例,展示如何压缩和修复Access数据库:```vbSub CompactRepairDatabase() Dim db As DAO.Database Set db = OpenDatabase
VB6.0与SQL Server2000的数据库连接方案比较.pdf
OLE DB(Object Linking and Embedding Database)是一种数据访问接口,提供了访问数据库的接口。OLE DB提供了对数据库的连接、查询和更新功能。
VB访问SQL Server数据库的几种方案.pdf
在整合VB6.0与SQL Server 2000时,能够发挥出意想不到的功效,并解决单一工具无法解决的问题。因此,掌握这些方案对于从事Visual Basic或数据库开发的程序员来说至关重要。
精彩编程与编程技巧-如何正确使用VB6访问Access2000数据库...
通过ADO,开发者可以利用OLE DB(Object Linking and Embedding Database)直接与数据库进行交互,这不仅提高了数据访问速度,也简化了代码的编写过程。


