Home > Back-end >  A question about the Advstringgrid
A question about the Advstringgrid

Time:10-10

Advstringgrid can read data from the database to read but write a detailed: why can't I write?? Only updates a
Ever have greatly advstringgrid updating data to database statement under reference thank you...
Procedure TForm1. Button1Click (Sender: TObject);
Var
J: Integer;
The begin
For j:=1 to AdvStringGrid1. Do the RowCount - 1
The begin
Edit1. Text:=IntToStr (AdvStringGrid1 RowCount);
UniQuery1. Close;
UniQuery1. SQL. The Clear;
UniQuery1. SQL. The Add (' SELECT * FROM dbo. CS_pubstaff ');
UniQuery1. Open;
UniQuery1. Edit;
UniQuery1. FieldByName (' cs_dep). Asstring:=advstringgrid1. Cells [j] 1,;
//UniQuery1 FieldByName (' cs_code). Asstring:=advstringgrid1. Cells [j] 2,;
//UniQuery1 FieldByName (' cs_name). Asstring:=advstringgrid1. Cells [3, j];
UniQuery1. Post;
end;
I like to write only updates a data but also wrong

CodePudding user response:

zijidingxia

CodePudding user response:

Var
J: Integer;
The begin
For j:=1 to AdvStringGrid1. Do the RowCount - 1
The 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. The Parameters. ParamByName (' cs_dep). Value:=advstringgrid1. Cells [j] 1,;
UniQuery1. The Parameters. ParamByName (' cs_code). Value:=advstringgrid1. Cells [j] 2,;
UniQuery1. The Parameters. ParamByName (' cs_name). Value:=advstringgrid1. Cells [3, j];
UniQuery1. ExecSQL;
end;

CodePudding user response:

quoted Confucius 2 floor response:
var
J: Integer;
The begin
For j:=1 to AdvStringGrid1. Do the RowCount - 1
The 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. The Parameters. ParamByName (' cs_dep). Value:=advstringgrid1. Cells [j] 1,;
UniQuery1. The Parameters. ParamByName (' cs_code). Value:=advstringgrid1. Cells [j] 2,;
UniQuery1. The Parameters. ParamByName (' cs_name). Value:=advstringgrid1. Cells [3, j];
UniQuery1. ExecSQL;
end;

Thank you I also tried this method but when users to edit the data or the next open doesn't work this method can only do insert this will create duplicate data can't update the entire table

CodePudding user response:

Upstairs are so clear, writing about some conditions can be achieved
  • Related