This code gets the StringGrid contents per row with '|' as a separator.
procedure TForm1.datas();
var
iRow: integer;
RowData : string;
begin
{get stringgrid content}
for iRow := 1 to Form7.StringGrid1.RowCount -1 do // count rows
begin
RowData := Form7.StringGrid1.Cells[0, iRow] + '|' + Form7.StringGrid1.Cells[1, iRow] + '|' + Form7.StringGrid1.Cells[2, iRow] + '|' + Form7.StringGrid1.Cells[3, iRow] + '|' + Form7.StringGrid1.Cells[4, iRow] + '|' + Form7.StringGrid1.Cells[5, iRow] + '|';
names := RowData; // it only get the last row in string grid :(
end;
end;
This code is for saving the data to the database:
{SAVE}
procedure TForm1.SaveBtnClick(Sender: TObject);
begin
datas; // get data
with SQLQuery4 do
begin
if RecordCount = 0 then
begin
close;
SQL.Text := 'Insert into my_db(names) values(:names)';
Params.ParamByName('names').AsString := names;
ExecSQL;
SQLTransaction4.Commit;
Close;
ShowMessage('Records Successfully Saved!');
end;
end;
end;
I want to save all of the StringGrid rows into one database column, but it only saves the data of the last row :(
I want to save it like this in my DB column:
A|B|C|D|E| // first row
F|G|H|I|J| // second row