你用基ADO对象试,以下是代码:判定是按编号或姓名查找:dim txt as string
if checkbox.text="编号" then
txt=textbox1.text
else
txt=textbox2.text
end if dim com as adodb.connection
dim sql as string
set com=new adodb.connection
com.connectionstring=""
com.open
sql="select * from 表名 where 编号/姓名=‘ ” & txt & '" "
dbgrid.datesource=com.execute sql 你试,我回去给你看看!

解决方案 »

  1.   

    谢谢,我想知道dbgrid它有没有什么属性可以让我自由定义字段的显示位置与字段的显示名(指dbgrid 最上面一行的那些虚字段名)呢? 要用代码来搞,而不是在控件中用属性那种。
      

  2.   

    napsoft  请你解释  谢谢!dbgrid.datesource=com.execute sql 帮我解释一下你这句话的意思~~~~com.execute sql  这样直接写不就行了吗?只是查询而已,为什么需要复给DBgrid_
    .datesource 呢?
      

  3.   

    将adodc1的currytype属性改为cmdtext然后sql 语句写在adodc1的recordsource属性里。dbgrid绑定到adodc1就可以了。
       adodc1.recordsource="select * from 表名 where 编号/姓名=‘ ” & txt & '" "
      

  4.   

    dbgrid.datesource=com.execute sql 的意思将SQL语句在COM中执行并返回所有结果.但dbgrid不支持这个方法.我回去帮你看了.以下是代码:用ADO控件,在代码中能,
    adodc1.connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &  APP.PATH & "\数据库名;Persist Security Info=False"
    Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = "select * from 表名 where 条件"如果你要在dbgrid中显示指定的行和列,回答是这个控件没有这个属性.

       MSHFlexGrid1.Text = "Here"
        '   将文本放到第 3 行,第 3 列。
       MSHFlexGrid1.Col = 2
       MSHFlexGrid1.Row = 2
      

  5.   

    dim c as Column
    for each c In datagrid1.Columns
        select case c.DataField
               case "OrderID"
                    c.visible=True
                    c.Caption="订单号"
               case else
                    c.visible=flase
         end select
    next c
      

  6.   

    下面是用代码实现:
    dim con as ADODB.Connection '定义Connection类型
    dim res as ADODB.Recordset  '定义Recordset类型
    dim s_sql set con=New ADODB.Connection '创建Connection对象
    set res=New ADODB.Recordset  '创建Recordset对象con.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.path & "\dbname.mdb";Persist Security  Info=False" '连接数据库res.CursorLocation = adUseClient '设立游标(一定要写)if checkbox1=1 then
     s_sql="select * from tablename where id=" & textbox1
    end ifif checkbox2=1 then
     s_sql="select * from tablename where name=" & textbox2 
    end ifres.open s_sql,con,3,3 '获取记录集
    dbgrid.Datasource=res '为dbgrid付值.好了,这就是你想要的.还有就是如果你在数据库中设置了段落标题,自然就会在datagrid中显示.
    最后我有一个建议就是你最后用OptionButton控件来作选择按钮,因为你没有必要两个都选. :)