1,首先开启VB6.0时新建数据工程
2,双击窗体在弹出的窗体中追加控件:Command1,Text1,Adodc1,DataGrid1其中DataGrid1是用来显示查询结果,Adodc1用来导航查询,Text1用来输入查询命令,Command1用来执行查询,下面是详细代码Private Sub Command1_Click()On Error GoTo err If Trim(Me.Text1.Text) "" Then If Adodc_Grid(Trim(Me.Text1.Text), Me.Adodc1, Me.DataGrid1) = True Then MsgBox "查询成功" Else '失败 End If Else MsgBox "请输入SQL查询语句" Exit Sub End If Exit Suberr: MsgBox err.DescriptionEnd SubPublic Function Adodc_Grid(Record_source As String, Adodc As Adodc, Grid As DataGrid) As Boolean '自定义的一个函数 On Error GoTo err Dim cnStr As String cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\student.mdb ;Persist Security Info=False" With Adodc .ConnectionString = cnStr .CommandType = adCmdText .RecordSource = Record_source Set Grid.DataSource = Adodc .RefreshEnd With Adodc_Grid = True Exit Functionerr: Adodc_Grid = FalseEnd Function