你用基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 你试,我回去给你看看!
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 你试,我回去给你看看!
.datesource 呢?
adodc1.recordsource="select * from 表名 where 编号/姓名=‘ ” & txt & '" "
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
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
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控件来作选择按钮,因为你没有必要两个都选. :)