程序报错 could not convert variant of type (string) into type (double)

程序可以运行,功能是把excel中的数据导入到服务器sqlser,为什么会报错无法转换成double格式?

我在sqlser中的数据格式试过char,vchar,nvchar等等,都是报这个错,程序中并没有转换格式啊。

procedure TForm1.Button1Click(Sender: TObject);
var ExcelApp, WorkBook,ExcelRowCount:Variant;
var i:integer;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
WorkBook := ExcelApp.WorkBooks.Open(edit1.Text);

ExcelApp.Visible := false;//设置excel是否可见
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
for i := 1 to excelrowcount + 1 do
begin
if ((excelapp.Cells[i,1].Value = '') and (ExcelApp.Cells[i,2].Value = '')) then exit
else
with ADOQuery1 do
begin
sql.add('insert into Table_1 (bs,hb) values (:bs,:hb)');

ADOQuery1.parameters.parambyname('bs').value:=(ExcelApp.Cells[i,1].Value);//断点显示在这里出错。/
ADOQuery1.parameters.parambyname('hb').value:=(ExcelApp.Cells[i,2].Value);
end;
end;
finally
WorkBook.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
WorkBook := Unassigned;
end;
end;
end.


回答:
如果 Variant 的值为 NULL 或空串,显然不能转换为 Double ,赋值语句左边类型是 Double ,右边类型是存储的 string 的 Variant ,需要在赋值之前进行验证。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值