VB中把查询后在datagrid显示的数据保存到新的access数据库的新表中? 5
这个是查询的代码:PrivateSubCommand1_Click()DimcnAsADODB.ConnectionDimrsAsADODB.RecordsetDimsq...
这个是查询的代码:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Dim sql2 As String
Dim fx1 As Boolean
Dim fx2 As Boolean
Dim stdtime1 As String
Dim stdtime2 As String
If Option1.Value Then
If Trim(Combo1.Text) = "" Then
MsgBox "产品名称不能为空!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
Exit Sub
Else
fx1 = True
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\大四\毕业设计\数据库\conn.mdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Properties("Initial Fetch Size") = 2
rs.Properties("Background Fetch Size") = 4
sql = "select * from dh where 产品名称='" & Combo1.Text & "'"
rs.Open sql, cn, adOpenStatic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rs
rs.Requery
End If
End If
end sub
然后不会保存到新表了,要点击报表打印按钮,保存到新表,然后实现打印,
Private Sub Command3_Click()
xsReport1.Show
End Sub
这个是窗体: 展开
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Dim sql2 As String
Dim fx1 As Boolean
Dim fx2 As Boolean
Dim stdtime1 As String
Dim stdtime2 As String
If Option1.Value Then
If Trim(Combo1.Text) = "" Then
MsgBox "产品名称不能为空!", vbOKOnly + vbExclamation, "警告"
Combo1.SetFocus
Exit Sub
Else
fx1 = True
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\大四\毕业设计\数据库\conn.mdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Properties("Initial Fetch Size") = 2
rs.Properties("Background Fetch Size") = 4
sql = "select * from dh where 产品名称='" & Combo1.Text & "'"
rs.Open sql, cn, adOpenStatic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rs
rs.Requery
End If
End If
end sub
然后不会保存到新表了,要点击报表打印按钮,保存到新表,然后实现打印,
Private Sub Command3_Click()
xsReport1.Show
End Sub
这个是窗体: 展开
展开全部
新表的结构跟原先的表一致?
可以跟查询过程一样获取数据,rsNew 用于打开新表:
sql = "select * from dh where 产品名称='" & Combo1.Text & "'"
rs.Open sql, cn, adOpenStatic, adLockOptimistic, adCmdText
rsNew.Open "select * from dhNew" , cn, adOpenStatic, adLockOptimistic, adCmdText
然后复制数据
do until rs.EOF
rsNew.AddNew
for i=0 to rs.Fields.count-1
rsNew(i)=rs(i)
next i
rs.MoveNext
rsNew.Update
loop
打印如果是用控件,一般也支持记录集,可以把 rs 直接设置为控件的记录源(rs需要是窗体级变量),就不用保存到数据库了。
可以跟查询过程一样获取数据,rsNew 用于打开新表:
sql = "select * from dh where 产品名称='" & Combo1.Text & "'"
rs.Open sql, cn, adOpenStatic, adLockOptimistic, adCmdText
rsNew.Open "select * from dhNew" , cn, adOpenStatic, adLockOptimistic, adCmdText
然后复制数据
do until rs.EOF
rsNew.AddNew
for i=0 to rs.Fields.count-1
rsNew(i)=rs(i)
next i
rs.MoveNext
rsNew.Update
loop
打印如果是用控件,一般也支持记录集,可以把 rs 直接设置为控件的记录源(rs需要是窗体级变量),就不用保存到数据库了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询