我现在excel表中有itemno ,desc, ttr,mmf几个字段的数据;数据库除了Excel中的几个字段外,还有几个字段; 现在我要用Excel中的数据去更新数据库相关数据;!我该怎么办?
我的思路是这样的: 用excel中的itemno与数据库中的itemno相比较,如果itemno相同就用excel的数据去修改数据库中对应的数据; 在excel中逐条取数据;这样的话我怎么获得excel的记录条数呢?
我的思路是这样的: 用excel中的itemno与数据库中的itemno相比较,如果itemno相同就用excel的数据去修改数据库中对应的数据; 在excel中逐条取数据;这样的话我怎么获得excel的记录条数呢?
对数据集进行操作
qry:tadoquery;
beginqry :=TADOQuery.Create(nil);
try
qry.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\1.xls;Extended Properties=Excel 8.0';
with qry do
begin
Close;
sql.Clear;
sql.Add('select * from [sheet1$]');
open;
end;
finally
qry.free;
end;
end;
用3个edit作为条件,如果为空就算没有
实例如下procedure TForm1.Button1Click(Sender: TObject);
var str:string;
begin
str:='where ';
if edit1.Text <>'' then
str := str + '职位 like ''%'+trim(edit1.Text)+'%'' OR ';
if edit2.Text <>'' then
str := str + '职位 like ''%'+trim(edit2.Text)+'%'' OR ';
if edit3.Text <>'' then
str := str + '职位 like ''%'+trim(edit3.Text)+'%'' OR ';
if length(str)<7 then//防止一个条件也没有的
str:='';
if rightstr(str,3)='OR ' then
str:=leftstr(str,length(str)-3); str := 'Select * from [sheet1$] '+str;
showmessage(str);end;
for i:=0 to Memo2.Lines.Count-1 do
begin
if i=0 then
SqlStr:=SqlStr+' and A.INVNUMBER='+Memo2.Lines.ValueFromIndex[i]
else
SqlStr:=SqlStr+' or A.INVNUMBER='+Memo2.Lines.ValueFromIndex[i];
end;现在问题是我上面的代码想配对"'"引号总是不行;
我这段代码不管有多少条件我都不怕; 大家帮忙看看引号问题好吗?
for i:=0 to Memo2.Lines.Count-1 do
begin
if i=0 then
SqlStr:=SqlStr+' and A.INVNUMBER='''+Memo2.Lines.ValueFromIndex[i]+''' '
else
SqlStr:=SqlStr+' or A.INVNUMBER='''+Memo2.Lines.ValueFromIndex[i]''' ';
end;