dim conn as new adodb.connection with conn if .state = adstateopen Then .close .connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False" .Open end with
dim conn as new adodb.connection dim rs as new adodb.recordset with conn if .state = adstateopen Then .close .connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False" .Open end withif rs.state=adstateopen then rs.close rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly if rs.recordcount=0 then msgbox "没有符合条件的记录!",48,"提示" else msgobx "共有记录" & rs.recordcount & "条" end if rs.close conn.close
还有谁能答复一下!好象跟 ado 或 dao 的版本也有关系呀,能否给段通用的代码?
Private Sub Form_Load() Dim strConn As String Dim pubConn As New ADODB.Connection Dim rsTable As New ADODB.Recordset Dim strSQL As String 'Access 2000ªº³s±µ strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\North.mdb;Persist Security Info=False" pubConn.Open strConn rsTable.CursorLocation = adUseClient strSQL = "select * from TableName" rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic Set DataGrid1.DataSource = rsTableEnd Sub
我的代码如下: Private Sub Form_Load() Dim dfpath As String '定义 Dim strConn As String Dim pubConn As New ADODB.Connection Dim rsTable As New ADODB.Recordset Dim strSQL As String
dfpath = App.Path If Right(dfpath, 1) <> "\" Then dfpath = dfpath & "\" strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dfpath & "DataBase\POS97.mdb;Persist Security Info=False" pubConn.Open strConn rsTable.CursorLocation = adUseClient strSQL = "select * from bmem" rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic '我的窗体上有Adodc 控件,名称为Adodc1,请问如何连接到 该控件上 End Sub
现有问题: 1. 在 2 楼 Leftie(左手,为人民币服务) 的答复中有: if .state = adstateopen Then .close if rs.state=adstateopen then rs.close 不知这两句是什么意思??? 2. 在打开表 的代码中 楼上有 2 为弟兄的答复少不一致: rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic 请问以上2 句代码最后 2 个参数不一样,其意思是什么,有区别吗?
Option ExplicitPrivate m_Conn As ADODB.Connection Private m_Cmd As ADODB.Command Public m_Rs As ADODB.Recordset Public Function ConnectToServer(ByVal strDBName As String) As Boolean On Error GoTo ERR_HANDLE: Set m_Conn = New ADODB.Connection m_Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName
m_Conn.ConnectionTimeout = 30 m_Conn.Open ConnectToServer = True Exit Function
End FunctionPrivate Sub Class_Terminate() On Error Resume Next If Not (m_Rs Is Nothing) Then m_Rs.Close Set m_Rs = Nothing If Not (m_Conn Is Nothing) Then m_Conn.Close Set m_Conn = Nothing End SubPublic Function GetRecordset(ByVal strSQL As String) As Boolean On Error GoTo ERR_HANDLE:
with conn
if .state = adstateopen Then .close
.connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False"
.Open
end with
假设有表 “tab1”和字段“age”。
能否把 查询 表 “tab1”中字段 “age”=25 的所有记录的语句也写一下!
dim rs as new adodb.recordset
with conn
if .state = adstateopen Then .close
.connectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Mode=ReadWrite;Persist Security Info=False"
.Open
end withif rs.state=adstateopen then rs.close
rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
if rs.recordcount=0 then
msgbox "没有符合条件的记录!",48,"提示"
else
msgobx "共有记录" & rs.recordcount & "条"
end if
rs.close
conn.close
还有谁能答复一下!好象跟 ado 或 dao 的版本也有关系呀,能否给段通用的代码?
Dim strConn As String
Dim pubConn As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim strSQL As String 'Access 2000ªº³s±µ
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\North.mdb;Persist Security Info=False" pubConn.Open strConn rsTable.CursorLocation = adUseClient
strSQL = "select * from TableName"
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsTableEnd Sub
Private Sub Form_Load()
Dim dfpath As String '定义
Dim strConn As String
Dim pubConn As New ADODB.Connection
Dim rsTable As New ADODB.Recordset
Dim strSQL As String
dfpath = App.Path
If Right(dfpath, 1) <> "\" Then dfpath = dfpath & "\"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dfpath & "DataBase\POS97.mdb;Persist Security Info=False"
pubConn.Open strConn rsTable.CursorLocation = adUseClient
strSQL = "select * from bmem"
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
'我的窗体上有Adodc 控件,名称为Adodc1,请问如何连接到 该控件上
End Sub
请问:
就以上代码,如何连接到我的 数据控件 Adodc 控件,名称为Adodc1 。
Adodc1.ConnectionString = strConn
Adodc1.RecordSource = strSQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
现有问题:
1. 在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
if .state = adstateopen Then .close
if rs.state=adstateopen then rs.close
不知这两句是什么意思???
2. 在打开表 的代码中 楼上有 2 为弟兄的答复少不一致:
rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
请问以上2 句代码最后 2 个参数不一样,其意思是什么,有区别吗?
Private m_Cmd As ADODB.Command
Public m_Rs As ADODB.Recordset
Public Function ConnectToServer(ByVal strDBName As String) As Boolean
On Error GoTo ERR_HANDLE: Set m_Conn = New ADODB.Connection
m_Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBName
m_Conn.ConnectionTimeout = 30
m_Conn.Open
ConnectToServer = True
Exit Function
ERR_HANDLE:
MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
ConnectToServer = False
End FunctionPublic Function ExecuteSQL(ByVal strSQLQuery As String) As Boolean
On Error GoTo ERR_HANDLE:
Set m_Cmd = New Command
With m_Cmd
.ActiveConnection = m_Conn
.CommandTimeout = 30
.CommandType = adCmdText
.CommandText = strSQLQuery
.Execute
End With
ExecuteSQL = True
Set m_Cmd = Nothing
Exit Function
ERR_HANDLE:
MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
ExecuteSQL = False
End FunctionPrivate Sub Class_Terminate()
On Error Resume Next
If Not (m_Rs Is Nothing) Then m_Rs.Close
Set m_Rs = Nothing
If Not (m_Conn Is Nothing) Then m_Conn.Close
Set m_Conn = Nothing
End SubPublic Function GetRecordset(ByVal strSQL As String) As Boolean
On Error GoTo ERR_HANDLE:
Set m_Rs = New Recordset
m_Rs.Open strSQL, m_Conn, adOpenDynamic, adLockOptimistic
GetRecordset = True
Exit Function
ERR_HANDLE:
MsgBox "Error NO.:" & Err.Number & vbCrLf & "Error Description:" & Err.Description, vbCritical + vbOKOnly, "Error"
GetRecordset = False
End Function
1. 在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
if .state = adstateopen Then .close
if rs.state=adstateopen then rs.close
不知这两句是什么意思???
2. 在打开表 的代码中 楼上有 2 为弟兄的答复少不一致:
rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
请问以上2 句代码最后 2 个参数不一样,其意思是什么,有区别吗?
1. 在 2 楼 Leftie(左手,为人民币服务) 的答复中有:
if .state = adstateopen Then .close
if rs.state=adstateopen then rs.close
不知这两句是什么意思???解释:这两句是判断RecordSet的状态,目的是关闭记录集。 2. 在打开表 的代码中 楼上有 2 为弟兄的答复少不一致:
rs.open "select * from tab1 where [age]=25",conn,adopenkeyset,adlockreadonly
rsTable.Open strSQL, pubConn, adOpenDynamic, adLockOptimistic
请问以上2 句代码最后 2 个参数不一样,其意思是什么,有区别吗?解释:第一个参数是游标,第二个参数是锁定方式上面介绍的都是ADO的语法,如果要用DAO来解决的话,只需要将DAO 3.51换成DAO 4.0就可以了,源程序不需要做任何修改!!