Query2.Close;
with StringGrid1 do begin
m := RowCount;
for j := 1 to m -3 do begin
ReDM := Cells[1,j];
ReSL := Cells[5,j];
Query2.Sql.Clear;
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+',)');
end;
end;
Query2.ExecSQL;
老是提示出错,错在什么地方?正确的做法是什么?
with StringGrid1 do begin
m := RowCount;
for j := 1 to m -3 do begin
ReDM := Cells[1,j];
ReSL := Cells[5,j];
Query2.Sql.Clear;
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+',)');
end;
end;
Query2.ExecSQL;
老是提示出错,错在什么地方?正确的做法是什么?
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values (''''+QuotedStr(BM)+'''',''''+QuotedStr(ReDM)+'''',''''+QuotedStr(ReSL)+'''')');
Query2.Close;
with StringGrid1 do begin
m := RowCount;
for j := 1 to m -3 do begin
ReDM := Cells[1,j];
ReSL := Cells[5,j];
Query2.Sql.Clear;
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+',)'); Query2.ExecSQL;
end;
end;
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+QuotedStr(BM)+''','''+QuotedStr(ReDM)+''','''+QuotedStr(ReSL)+''',)');
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+')');
//调试的时候如果有错就把SQL语句放到数据库查询分析器中调试下先~~
//那里过了,Delphi里才能过~~begin
Query2.Close;
Query2.SQL.Clear;
with StringGrid1 do begin
M := RowCount;
for J := 1 to RowCount - 3 do begin
ReDM := Cells[1, J];
ReSL := Cells[5, J];
Query2.SQL.Add(Format(
'Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values (%s,%s,%s);', [
QuotedStr(BM), QuotedStr(ReDM), QuotedStr(ReSL)]));
end;
end;
try
Query2.ExecSQL;
except
{ TODO : 异常处理 }
end;
end;
m := RowCount; //假如m=3
for j := 1 to m -3 do begin //不运行
ReDM := Cells[1,j];
ReSL := Cells[5,j];
// Query2.Sql.Clear; 在这里有什么用??反正都是执行的最后一条
// 或者把后面的query2.execsql提到前面来
// Query2.Sql.text:='Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+BM+''','''+ReDM+''','''+ReSL+'''';//我喜欢用text
//query.sql.execsql; 上面3句建议同时使用
end;
end;
// Query2.ExecSQL;
with StringGrid1 do begin
m := RowCount;
for j := 1 to m -3 do begin
ReDM := Cells[1,j];
ReSL := Cells[5,j];
Query2.Close;
Query2.Sql.Clear;
Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+QuotedStr(BM)+''','''+QuotedStr(ReDM)+''','''+QuotedStr(ReSL)+''')');
Query2.ExecSQL;
end;
end;