access多表查询后修改数据问题
我现在建立了一个数据库,库中有多个相同结构的表,数量未知,现在我要以日期查询数据库中的记录,这个要怎么做?比如我现在有2012,2013两个表,表的字段相同(序号,检测日期,产品编号,检测结果,检验员,备注),我要以检测日期来检索两个表中的记录,并给Datagrid显示(序号要改,重新从1开始),可以修改备注。
我的程序:
mysql = "select * from (select * from 2012 union all select * from 2013) tem where 检测日期 between # " & Format(myDTPicker_qi, "yyyy/mm/dd") & " # and # " & Format(myDTPicker_zhi + 1, "yyyy/mm/dd") & " # "
myrs.ActiveConnection = mycn
myrs.Open mysql, mycn, adOpenStatic, adLockPessimistic
myzsl = myrs.RecordCount
'修改显示的序号''''''''''''''''''''''''''''''''''''''
Dim myrs_row As Integer
If myzsl <> 0 Then
myrs.MoveFirst
For myrs_row = 0 To myzsl - 1
myrs.Fields(0) = myrs_row + 1
myrs.MoveNext
Next myrs_row
End If
Set my_DataGrid1.DataSource = myrs '连接数据库
现在的情况是如果没有修改显示的序号,datagrid可以显示出来,但是加上修改显示的序号,就会报错,多步操作产生错误,请问上述功能怎样实现 数据库 多表查询 datagrid --------------------编程问答-------------------- 看看这个例子:
Private Sub Form_Load()
objRecordset.ActiveConnection = objConnection
'ADO connection 对象
objRecordset.CursorLocation = adUseClient
' 必须使用 client-side 游标
objRecordset.CursorType = adOpenStatic
' client-sided server 游标必须使用此类型
objRecordset.LockType = adLockBatchOptimistic
'Northwind 数据库
objRecordset.Open "SELECT * FROM Customers JOIN Orders ON " & _
"Customers.CustomerID = Orders.CustomerID WHERE city = " & _
"'London' ORDER BY CustomerID"
objRecordset.Properties("Unique Table").Value = "Orders"
objRecordset.Properties("Resync Command").Value = "SELECT * FROM " & _
"(SELECT * FROM Customers JOIN Orders ON Customers.CustomerID = " & _
"Orders.CustomerID WHERE city = 'London' ORDER BY CustomerID) " & _
"WHERE Orders.OrderID = ?"
objRecordset.ActiveConnection = Nothing
'disconnected ADO recordset
Set grdTest.Datasource = objRecordset
End Sub
Private Sub Save()
objRecordset.ActiveConnection = objConnection
' 仅为保存目的重新连接
objRecordset.UpdateBatch
' 不要忘记检查 ADO 错误集合
objRecordset.ActiveConnection = Nothing
' 再断开
End Sub
补充:VB , 数据库(包含打印,安装,报表)