你好,我想用VB做个查询界面,怎么将SQL语句嵌入进去
展开全部
使用ADO数据数据对象或控件,参考以下代码。
Private Sub Form_Load()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim ARR
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wdOld.mdb;Persist Security Info=False"
sql = "select 故障名称 from guzhang_bm"
rs.Open sql, cnn
Combo1.Text = "故障名称"
Do While Not rs.EOF
Combo1.AddItem rs("故障名称")
rs.MoveNext '打开表
Loop
rs.Close
cnn.Close
End Sub
Private Sub Command1_Click()
Dim sqlstr As String
sqlstr = "select * from jishijilu"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\wdOld.mdb;Persist Security Info=False"
Adodc1.RecordSource = sqlstr
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Text1 = Adodc1.Recordset.RecordCount
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询