vb怎么样实现点击查找按钮,打开form2窗体,并把查询结果显示在form2 ?
form1窗体有一个文本框text1和一个查找按钮Command1,同一个文件里有一个db1.mdb.我想实现点击查找按钮,然后把查询的结果显示在form2的datagr...
form1窗体有一个文本框text1和一个查找按钮Command1,同一个文件里有一个db1.mdb.我想实现点击查找按钮,然后把查询的结果显示在form2的datagrid里。刚开始学vb,望写出完整的代码,在此谢谢了!
我用的是ADO连接的,没有用adodc控件,谢谢各位了! 并且在form1中已成功连接数据库,form1代码如下:
Dim ZhuCe As ADODB.Connection
Dim rstZhuCe As ADODB.Recordset
Dim cmmZhuCe As ADODB.Command
Private Sub Command1_Click()
Set cmmZhuCe = New ADODB.Command
Set cmmZhuCe.ActiveConnection = ZhuCe
Set Text1.DataSource = rstZhuCe
Set Text2.DataSource = rstZhuCe
Text1.DataField = "名称"
Text2.DataField = "规格"
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
Set ZhuCe = New ADODB.Connection
ZhuCe.CursorLocation = adUseClient
ZhuCe.Open "Provider=Microsoft.jet.oledb.4.0;Data source=" & App.Path & "\db1.mdb"
Set rstZhuCe = New ADODB.Recordset
Set rstZhuCe.ActiveConnection = ZhuCe
rstZhuCe.Open "select * from 价格表", ZhuCe, adOpenStatic, adLockOptimistic
End Sub
其实问题中的text1和Command1是程序中的text3和Command3,谢谢了! 展开
我用的是ADO连接的,没有用adodc控件,谢谢各位了! 并且在form1中已成功连接数据库,form1代码如下:
Dim ZhuCe As ADODB.Connection
Dim rstZhuCe As ADODB.Recordset
Dim cmmZhuCe As ADODB.Command
Private Sub Command1_Click()
Set cmmZhuCe = New ADODB.Command
Set cmmZhuCe.ActiveConnection = ZhuCe
Set Text1.DataSource = rstZhuCe
Set Text2.DataSource = rstZhuCe
Text1.DataField = "名称"
Text2.DataField = "规格"
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
Set ZhuCe = New ADODB.Connection
ZhuCe.CursorLocation = adUseClient
ZhuCe.Open "Provider=Microsoft.jet.oledb.4.0;Data source=" & App.Path & "\db1.mdb"
Set rstZhuCe = New ADODB.Recordset
Set rstZhuCe.ActiveConnection = ZhuCe
rstZhuCe.Open "select * from 价格表", ZhuCe, adOpenStatic, adLockOptimistic
End Sub
其实问题中的text1和Command1是程序中的text3和Command3,谢谢了! 展开
展开全部
Private Sub Command3_Click()
rstZhuCe.Open "select * from 价格表 where 名称='" & text3.text & "' or 规格='" & text3.text & "'", ZhuCe, adOpenStatic, adLockOptimistic
Set Form2.DataGrid1.DataSource = rstZhuCe
Form2.Show VbModal
End Sub
你试一试,我没验证
rstZhuCe.Open "select * from 价格表 where 名称='" & text3.text & "' or 规格='" & text3.text & "'", ZhuCe, adOpenStatic, adLockOptimistic
Set Form2.DataGrid1.DataSource = rstZhuCe
Form2.Show VbModal
End Sub
你试一试,我没验证
展开全部
Dim ZhuCe As ADODB.Connection
Dim rstZhuCe As ADODB.Recordset
Dim cmmZhuCe As ADODB.Command
要写在模块里,为全局变量名。
form2的
Private Sub Form_Load()
Set Form2.DataGrid1.DataSource = rstZhuCe
end sub
Dim rstZhuCe As ADODB.Recordset
Dim cmmZhuCe As ADODB.Command
要写在模块里,为全局变量名。
form2的
Private Sub Form_Load()
Set Form2.DataGrid1.DataSource = rstZhuCe
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用ADO控件绑定你的DATAGRID就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询