|
以下是delphi 代码实例,修改一下就可以了。
- //第一步:连接数据库
- constr:='Provider=Microsoft.Jet.OLEDB.4.0;'+
- 'User ID=Admin;Jet OLEDB:Database Password=qdsafetyyf;'+
- 'Data Source='+ExtractFilePath(Application.ExeName)+'JNJKSJK.mdb;'+
- 'Persist Security Info=true';
- adoquery1.ConnectionString := constr;
- form1.ADOQuery1.ConnectionString:=constr;
- //第二步:查询记录
- var
- i,j:integer;
- newitem :tlistitem;
- ykmc:string;
- begin
- ykmc:=edit1.Text;
- ADOQuery1.Close;
- ADOQuery1.SQL.Clear;
- adoquery1.SQL.Add('select * from ykxx where ykdw='''+ykmc+'''');//注意语法格式,'''+ykmc+'''必须是三对单引号
- ADOQuery1.Open;
- ListView1.Clear;
- if edit1.Text='' then
- begin
- showmessage('请输入要查询的业扩单位的名称');
- end;
- if (adoQuery1.RecordCount>0) and (edit1.Text<>'') then
- begin
- for i:=1 to AdoQuery1.RecordCount do
- begin
- newitem:=ListView1.Items.Add;
- newitem.Caption:=AdoQuery1.FieldByName('BH').AsString;
- newitem.SubItems.Add(AdoQuery1.FieldByName('YKDW').AsString);
- newitem.SubItems.Add(AdoQuery1.FieldByName('YKSJ').AsString);
- newitem.SubItems.Add(AdoQuery1.FieldByName('YKNR').AsString);
- ADOQuery1.Next;
- end;
- j:=listview1.Items.Count;
- edit2.Text:=inttostr(j)+'条';
- end;
- if (adoquery1.RecordCount =0) and (edit1.Text<>'') then
- begin
- showmessage('没有符合条件的记录!!!!');
- edit2.Text:='0'+'条';
- end;
- end;
复制代码 |
|