参考: for J := 1 to I do begin B := SGridModal.Cells[0, J]; C := SGridModal.Cells[1, J]; SqlText := 'insert into SubFormatTb (formatId, subName, formatData) values (' + sFormatId + ',''' + B + '''' + ',''' + C + '''' + ')'; ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Text := sqlText; ADOQuery1.ExecSQL; end; ADOQuery1.Close;
就是楼上的,循环insert 混点分了^_^
var row,col:integer; str:string; begin row := StringGrid1.Row; col := StringGrid1.Col; str := StringGrid1.Cells[col,row]; AdoQuery.Edit; AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString := str; AdoQuery.Post; end;读出时 StringGrid1.Cells[col,row] := AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString
为了这一百分…… procedure TForm1.Button1Click(Sender: TObject); var I: integer; begin //将StringGrid数据写入到Access表Table1中 ADOQuery1.SQL.Text := 'SELECT * FROM Table1'; ADOQuery1.Open; //StringGrid第1列对应的Access表列名01 for I := 1 to StringGrid1.RowCount - 1 do begin ADOQuery1.Edit; ADOQuery1.FieldByName('01').AsString := StringGrid1.Cells[1, I]; ADOQuery1.Post; end; //将Access表中数据显示到StringGrid ADOQuery1.SQL.Text := 'SELECT * FROM Table1'; ADOQuery1.Open; StringGrid1.RowCount := ADOQuery1.RecordCount; ADOQuery1.First; for I := 1 to ADOQuery1.RecordCount do begin StringGrid1.Cells[1, I] := ADOQuery1.FieldByName('01').AsString; ADOQuery1.Next; end; end;
procedure Tcheckform.newstringgrid(Sender:Tobject); //wyy 初始化 var List: TStrings; begin List := TStringList.Create; List.CommaText := '日期,周期,卵巢及卵泡情况,宫内膜,其他'; StringGrid1.Rows[0] := List; List.Free; List := TStringList.Create; List.CommaText := ',天,左侧卵巢卵泡大小为*mm,mm,无'; StringGrid1.Rows[1] := List; StringGrid1.Rows[2] := List; StringGrid1.Rows[3] := List; StringGrid1.Rows[4] := List; StringGrid1.Rows[5] := List; StringGrid1.Rows[6] := List; List.Free; StringGrid1.ColWidths[2] := 200; endprocedure Tcheckform.readstringgrid(Sender:Tobject); var c,r,number:integer; Field:Tstring; begin { with dm.qrystringgrid do //读取数据库信息 begin for c:=0 to 4 do for r:=1 to 6 do begin number:=r*10+c; stringgrid1.Cells[c,r]:=fields[number].asstring; end end; } with dm.qrystringgrid do begin for c:= 0 to 4 do for r:= 1 to 6 do number:=r*10+c; Field := FieldByName(number); if Field <> Nil then stringgrid1.Cells[c,r]:= Field.AsString; end end StringGrid1.Cells[col,row] := AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsStringend;procedure Tcheckform.savestringgrid(Sender:Tobject); //保存stringgrid 保存表格信息,如果多于6行,自动保存后5行 { with dm.qrystringgrid do begin if stringgrid1.cell[0,6]:='' then begin stringgrid1.cells[o,1]:=fieldbyname('01').asstring; end else begin stringgrid1.cells[o,2]:=fieldbyname('01').asstring; end; end; } var row,col:integer; str:string; begin row := StringGrid1.Row; col := StringGrid1.Col; str := StringGrid1.Cells[col,row]; AdoQuery.Edit; AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString := str; AdoQuery.Post; end; 这个是我加的几个函数的代码,一个用于初始化,就是无病人信息时显示,2是读取病人的信息,3是存 我不太清楚怎么存不到数据库里面有个access数据库,表名是stringgrid
procedure Tjhdform.savetojhddata(); var i,j:integer; slddata_addi,slddata_addv:AnsiString; straddi,straddv:string; begin DM.Query1.SQL.Clear; DM.Query1.Close; straddi:='INSERT INTO modedbthr('; straddv:='VALUES (' ; for i:= 0 to 13 do begin if (i<13) then begin slddata_addi:=slddata_addi+dbname[i]+',' ; slddata_addv:=slddata_addv+':'+dbname[i]+','; end else begin slddata_addv:=slddata_addv+':'+dbname[i] ; slddata_addi:=slddata_addi+dbname[i] ; end; end;
for i:= 1 to StringGrid1.rowCount -2 do begin DM.Query1.SQL.Clear; DM.Query1.SQL.Add(straddi+slddata_addi+')'); DM.Query1.SQL.Add(straddv+slddata_addv+')'); for j := 0 to 10 do begin if ((j=5)) then begin IF (StringGrid1.Cells[j+1,i]='')then DM.Query1.Parameters.ParamByName(dbname[j]).value:=0 else DM.Query1.Parameters.ParamByName(dbname[j]).value := StrToFloat(StringGrid1.Cells[j+1,i]); end else begin if(j=1) then begin IF (Length(StringGrid1.Cells[j+1,i])<2) then DM.Query1.Parameters.ParamByName(dbname[j]).value:='9'+copy(DELENULLSTR(DELEdotSTR(DELEhengSTR(FormatDateTime('yyyy-mm-dd-hh-mm-ss',Now )))),8,9)+inttostr(i) else DM.Query1.Parameters.ParamByName(dbname[j]).value := StringGrid1.Cells[j+1,i]; end else begin IF (StringGrid1.Cells[j+1,i]='')then DM.Query1.Parameters.ParamByName(dbname[j]).value:='-' else DM.Query1.Parameters.ParamByName(dbname[j]).value := StringGrid1.Cells[j+1,i]; end; end; end; DM.Query1.ExecSQL; end; END; DM.Query1.Close; ShowMessage('数据已保存!'); end;
begin
B := SGridModal.Cells[0, J];
C := SGridModal.Cells[1, J];
SqlText := 'insert into SubFormatTb (formatId, subName, formatData) values ('
+ sFormatId
+ ',''' + B + ''''
+ ',''' + C + ''''
+ ')';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := sqlText;
ADOQuery1.ExecSQL; end;
ADOQuery1.Close;
混点分了^_^
var
row,col:integer;
str:string;
begin
row := StringGrid1.Row;
col := StringGrid1.Col;
str := StringGrid1.Cells[col,row];
AdoQuery.Edit;
AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString := str;
AdoQuery.Post;
end;读出时
StringGrid1.Cells[col,row] := AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString
procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
begin
//将StringGrid数据写入到Access表Table1中
ADOQuery1.SQL.Text := 'SELECT * FROM Table1';
ADOQuery1.Open;
//StringGrid第1列对应的Access表列名01
for I := 1 to StringGrid1.RowCount - 1 do begin
ADOQuery1.Edit;
ADOQuery1.FieldByName('01').AsString := StringGrid1.Cells[1, I];
ADOQuery1.Post;
end; //将Access表中数据显示到StringGrid
ADOQuery1.SQL.Text := 'SELECT * FROM Table1';
ADOQuery1.Open;
StringGrid1.RowCount := ADOQuery1.RecordCount;
ADOQuery1.First;
for I := 1 to ADOQuery1.RecordCount do begin
StringGrid1.Cells[1, I] := ADOQuery1.FieldByName('01').AsString;
ADOQuery1.Next;
end;
end;
query 名称是qrystringgrid 表的名称是stringgrid 我不太清楚怎么指向...
在数据库里面的那个表中 有对应的6个字段 01 02 03 11 12 13cncharles
我不太理解网上买2维的表格你就用了1个变量表述啊??是不是我表达的不太好?
只是给了你一列的处理示范其他的你要自己去扩展了
使用时,取出来先解码为多行x多列,分布填到grid的每一个cell里
var List: TStrings;
begin
List := TStringList.Create;
List.CommaText := '日期,周期,卵巢及卵泡情况,宫内膜,其他';
StringGrid1.Rows[0] := List;
List.Free;
List := TStringList.Create;
List.CommaText := ',天,左侧卵巢卵泡大小为*mm,mm,无';
StringGrid1.Rows[1] := List;
StringGrid1.Rows[2] := List;
StringGrid1.Rows[3] := List;
StringGrid1.Rows[4] := List;
StringGrid1.Rows[5] := List;
StringGrid1.Rows[6] := List;
List.Free; StringGrid1.ColWidths[2] := 200;
endprocedure Tcheckform.readstringgrid(Sender:Tobject);
var
c,r,number:integer;
Field:Tstring;
begin
{ with dm.qrystringgrid do //读取数据库信息
begin
for c:=0 to 4 do
for r:=1 to 6 do
begin
number:=r*10+c;
stringgrid1.Cells[c,r]:=fields[number].asstring;
end
end; }
with dm.qrystringgrid do
begin
for c:= 0 to 4 do
for r:= 1 to 6 do
number:=r*10+c;
Field := FieldByName(number);
if Field <> Nil then
stringgrid1.Cells[c,r]:= Field.AsString;
end
end
StringGrid1.Cells[col,row] := AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsStringend;procedure Tcheckform.savestringgrid(Sender:Tobject);
//保存stringgrid 保存表格信息,如果多于6行,自动保存后5行
{ with dm.qrystringgrid do
begin
if stringgrid1.cell[0,6]:='' then
begin
stringgrid1.cells[o,1]:=fieldbyname('01').asstring;
end
else
begin
stringgrid1.cells[o,2]:=fieldbyname('01').asstring;
end;
end; }
var
row,col:integer;
str:string;
begin
row := StringGrid1.Row;
col := StringGrid1.Col;
str := StringGrid1.Cells[col,row];
AdoQuery.Edit;
AdoQuery.FieldByName(IntToStr(col)+IntToStr(row)).AsString := str;
AdoQuery.Post;
end;
这个是我加的几个函数的代码,一个用于初始化,就是无病人信息时显示,2是读取病人的信息,3是存
我不太清楚怎么存不到数据库里面有个access数据库,表名是stringgrid
var
i,j:integer;
slddata_addi,slddata_addv:AnsiString;
straddi,straddv:string;
begin
DM.Query1.SQL.Clear;
DM.Query1.Close;
straddi:='INSERT INTO modedbthr(';
straddv:='VALUES (' ;
for i:= 0 to 13 do
begin
if (i<13) then
begin
slddata_addi:=slddata_addi+dbname[i]+',' ;
slddata_addv:=slddata_addv+':'+dbname[i]+',';
end
else
begin
slddata_addv:=slddata_addv+':'+dbname[i] ;
slddata_addi:=slddata_addi+dbname[i] ;
end;
end;
for i:= 1 to StringGrid1.rowCount -2 do
begin
DM.Query1.SQL.Clear;
DM.Query1.SQL.Add(straddi+slddata_addi+')');
DM.Query1.SQL.Add(straddv+slddata_addv+')'); for j := 0 to 10 do
begin
if ((j=5)) then
begin
IF (StringGrid1.Cells[j+1,i]='')then DM.Query1.Parameters.ParamByName(dbname[j]).value:=0
else DM.Query1.Parameters.ParamByName(dbname[j]).value := StrToFloat(StringGrid1.Cells[j+1,i]);
end
else
begin
if(j=1) then
begin
IF (Length(StringGrid1.Cells[j+1,i])<2) then DM.Query1.Parameters.ParamByName(dbname[j]).value:='9'+copy(DELENULLSTR(DELEdotSTR(DELEhengSTR(FormatDateTime('yyyy-mm-dd-hh-mm-ss',Now )))),8,9)+inttostr(i)
else DM.Query1.Parameters.ParamByName(dbname[j]).value := StringGrid1.Cells[j+1,i];
end
else
begin
IF (StringGrid1.Cells[j+1,i]='')then DM.Query1.Parameters.ParamByName(dbname[j]).value:='-'
else DM.Query1.Parameters.ParamByName(dbname[j]).value := StringGrid1.Cells[j+1,i];
end;
end;
end;
DM.Query1.ExecSQL;
end;
END;
DM.Query1.Close;
ShowMessage('数据已保存!');
end;