我在往表里insert数据的时候,编译通过,但是程序执行的时候,出现异常,显示为general sql error,[microsoft],[odbc sql server driver],无效的数据格式!
try
dmod.Database.StartTransaction ;
with dmod.qrydata do
begin
close;
SQL.Text := 'delete from employee where emp_no='+#39+Empno+#39;
ExecSQL; close;
SQL.Text := 'insert into employee(emp_no,emp_name,emp_sex,emp_birthday' +chr(13) +
',emp_indate,emp_idcard,emp_address,emp_zipcode,emp_phone,emp_mobile,emp_type,emp_photo'+chr(13) +
',emp_re) values (:no,:name,:sex,:birthday,:indate,:idcard,:address' +chr(13) +
',:zipcode,:phone,:mobile,:type,:photo,:re)';
ParamByName('no').AsString := trim(edt_Empno.Text);
ParamByName('name').AsString := trim(edt_Empname.Text );
ParamByName('sex').AsString := trim(cbb_Sex.Text );
ParamByName('birthday').AsDate := dtp_Birthday.Date ;
ParamByName('indate').AsDate := dtp_Indate.Date ;
ParamByName('idcard').AsString := trim(edt_Idcard.Text );
ParamByName('address').AsString := trim(edt_Address.Text );
ParamByName('zipcode').AsString := trim(edt_Zipcode.Text );
ParamByName('phone').AsString:= trim(edt_Phone.Text );
ParamByName('mobile').AsString := trim(edt_mobile.Text );
ParamByName('type').AsString := StringGetChar(temp_type,'-') ;
if img_photo.Picture.Graphic <>nil then
begin
try
MemStream := TMemoryStream.Create ;
Img_photo.Picture.Graphic.SaveToStream(MemStream);
ParamByName('photo').LoadFromStream(MemStream,FtGraphic);
finally
MemStream := nil;
MemStream.Free ;
end;
end else ParamByName('photo').AsBlob :=''; ParamByName('re').AsString := mm_re.Lines.GetText;
ExecSQL;
end;
finally
try
dmod.Database.Commit ;
except
dmod.Database.Rollback ;
MessageBox(handle,'操作失败,请重试!','提示',mb_ok+mb_iconinformation);
result := false;
end;
end;
emp_no 为char
emp_name 为char emp_sexemp_birthday 为date
emp_indate为date,emp_idcard为char,emp_address为char,emp_zipcode为char,emp_phone为char,emp_mobile为char,emp_type为char,emp_photo为image ',emp_re为text
try
dmod.Database.StartTransaction ;
with dmod.qrydata do
begin
close;
SQL.Text := 'delete from employee where emp_no='+#39+Empno+#39;
ExecSQL; close;
SQL.Text := 'insert into employee(emp_no,emp_name,emp_sex,emp_birthday' +chr(13) +
',emp_indate,emp_idcard,emp_address,emp_zipcode,emp_phone,emp_mobile,emp_type,emp_photo'+chr(13) +
',emp_re) values (:no,:name,:sex,:birthday,:indate,:idcard,:address' +chr(13) +
',:zipcode,:phone,:mobile,:type,:photo,:re)';
ParamByName('no').AsString := trim(edt_Empno.Text);
ParamByName('name').AsString := trim(edt_Empname.Text );
ParamByName('sex').AsString := trim(cbb_Sex.Text );
ParamByName('birthday').AsDate := dtp_Birthday.Date ;
ParamByName('indate').AsDate := dtp_Indate.Date ;
ParamByName('idcard').AsString := trim(edt_Idcard.Text );
ParamByName('address').AsString := trim(edt_Address.Text );
ParamByName('zipcode').AsString := trim(edt_Zipcode.Text );
ParamByName('phone').AsString:= trim(edt_Phone.Text );
ParamByName('mobile').AsString := trim(edt_mobile.Text );
ParamByName('type').AsString := StringGetChar(temp_type,'-') ;
if img_photo.Picture.Graphic <>nil then
begin
try
MemStream := TMemoryStream.Create ;
Img_photo.Picture.Graphic.SaveToStream(MemStream);
ParamByName('photo').LoadFromStream(MemStream,FtGraphic);
finally
MemStream := nil;
MemStream.Free ;
end;
end else ParamByName('photo').AsBlob :=''; ParamByName('re').AsString := mm_re.Lines.GetText;
ExecSQL;
end;
finally
try
dmod.Database.Commit ;
except
dmod.Database.Rollback ;
MessageBox(handle,'操作失败,请重试!','提示',mb_ok+mb_iconinformation);
result := false;
end;
end;
emp_no 为char
emp_name 为char emp_sexemp_birthday 为date
emp_indate为date,emp_idcard为char,emp_address为char,emp_zipcode为char,emp_phone为char,emp_mobile为char,emp_type为char,emp_photo为image ',emp_re为text
高手快来抢分啊
你是试着看看你的数据类型是否有问题?
比如曾经Flaot 类型就出问题,后来我改用,double就OK啦。
是date类型的问题