Advstringgrid从数据库读取数据可以逐条读出 但是写入为什么不能写?? 只能更新一条
有没有大大有advstringgrid更新数据到数据库的语句参考下 谢谢....
procedure TForm1.Button1Click(Sender: TObject);
var
j:Integer;
begin
for j := 1 to AdvStringGrid1.RowCount-1 do
begin
Edit1.Text:=IntToStr(AdvStringGrid1.RowCount);
UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Add('SELECT * FROM dbo.CS_pubstaff');
UniQuery1.open;
UniQuery1.edit;
UniQuery1.FieldByName('cs_dep').asstring:= advstringgrid1.Cells[1,j];
// UniQuery1.FieldByName('cs_code').asstring:= advstringgrid1.cells[2,j];
// UniQuery1.FieldByName('cs_name').asstring:= advstringgrid1.cells[3,j];
UniQuery1.Post;
end;
我这样写只能更新一条数据 而且还是错的
有没有大大有advstringgrid更新数据到数据库的语句参考下 谢谢....
procedure TForm1.Button1Click(Sender: TObject);
var
j:Integer;
begin
for j := 1 to AdvStringGrid1.RowCount-1 do
begin
Edit1.Text:=IntToStr(AdvStringGrid1.RowCount);
UniQuery1.Close;
UniQuery1.SQL.Clear;
UniQuery1.SQL.Add('SELECT * FROM dbo.CS_pubstaff');
UniQuery1.open;
UniQuery1.edit;
UniQuery1.FieldByName('cs_dep').asstring:= advstringgrid1.Cells[1,j];
// UniQuery1.FieldByName('cs_code').asstring:= advstringgrid1.cells[2,j];
// UniQuery1.FieldByName('cs_name').asstring:= advstringgrid1.cells[3,j];
UniQuery1.Post;
end;
我这样写只能更新一条数据 而且还是错的
j: Integer;
begin
for j := 1 to AdvStringGrid1.RowCount-1 do
begin
Edit1.Text:=IntToStr(AdvStringGrid1.RowCount);
UniQuery1.SQL.Text := 'insert into CS_pubstaff(cs_dep, cs_code, cs_name) value(:cs_dep, :cs_code, :cs_name)';
UniQuery1.Parameters.ParamByName('cs_dep').Value := advstringgrid1.Cells[1,j];
UniQuery1.Parameters.ParamByName('cs_code').Value := advstringgrid1.Cells[2,j];
UniQuery1.Parameters.ParamByName('cs_name').Value := advstringgrid1.Cells[3,j];
UniQuery1.ExecSQL;
end;