Project Project1.exe raised exception class EOLeException with message"不能将值NULL插入列‘StockID',表"POS.dbo.Stock";列不允许有空值。INSERT失败。“Process stopped。Use Step or Run to continue。

解决方案 »

  1.   

    StockID的值 为空啊。 要么在数据库中 把表 POS.dbo.Stock 的  StockID的字段设为可空。
    如果数据重要,则一定要先给 StockID赋值 。
      

  2.   

    估计lz数据库里面该字段为键值,不能为空,但是在他的程序中insert的时候,改字段在随机的情况下出现了空。而他这个时候恰好没有判断该字段。所以就出现了很难跟踪调试的。以至于1个下午没改对。呵呵
      

  3.   

    这样
    试试
    if ISNULL(DATA) then
      insert into (StockID) values('')
    else
      insert into (StockID) values(DATA)
     
      

  4.   

    begin
      with ADOQuery2 do
         begin
           close;
           sql.clear;
           sql.add('select top 1 * from Stock order by StockID desc');
           open;
           first;
           if fieldbyname('StockDate').asstring=datetostr(Date) then
              edit1.text:=floattostr(fieldbyname('StockID').asfloat+1)
           else
              edit1.text:=floattostr(strtofloat(formatdatetime('yyyy""mm""dd',Date))*10000+1);     end;    with ADOQuery1 do
         begin
           close;
           sql.clear;
           sql.add('select  * from Stock  where StockID='+''''+edit1.text+'''');
           open;
           first;
           
         end;end;procedure TStockFrm.Button4Click(Sender: TObject);
    begin
        StockFrm.hide;
    end;procedure TStockFrm.Button1Click(Sender: TObject);
    begin
      if dbcombobox1.text='' then
         showmessage('请选择供货商!')
      else
       if dbcombobox2.text='' then
         showmessage('请选择入库货品!')
       else
        if dbedit4.text='' then
         showmessage('请填写入库数量!')
         else
          if dbedit5.text='' then
           showmessage('请填写入库单价!')
       else
        begin
        with ADOQuery2 do
         begin
           close;
           sql.clear;
           sql.add('insert into Stock (StockID,StockDate,FeederName,ProductName,');
           sql.add('ProductCode,Spec,Unit,RFStockPrice,UnitPrice,Quantity,Payment)values (' );
           sql.add(''''+edit1.text+''''+','+''''+edit2.text+''''+',');
           sql.add(''''+dbcombobox1.text+''''+','+''''+dbcombobox2.text+''''+',');
           sql.add(''''+dbcombobox3.text+''''+','+''''+dbedit1.text+''''+',');
           sql.add(''''+dbedit2.text+''''+','+''''+dbedit3.text+''''+',');
           sql.add(''''+dbedit4.text+''''+','+''''+dbedit5.text+''''+',');
           sql.add(''''+dbedit6.text+''''+')');
           execsql;
        end;
        with ADOQuery1 do
          begin
           close;
           sql.clear;
           sql.add('select  * from Stock where StockID='+''''+edit1.text+'''');
           
           open;
           first;
          end;
        showmessage('此货品添加成功!');
        end;
    大概的程序是这样的,,哪位高手帮帮忙啊,我看到有INSERT的就这个了
      

  5.   

    如果你edit1.text为空呢?lz是每次操作都出现这样的错误么?
      

  6.   

    edit1.text填的就是StockID,edit2.text填的是入库日期,运行后日期是自动显示当天的时间,我点击添加货品的时候,StockID也是自动根据日期来显示的,,我根本就没有机会去改,,
      

  7.   


    首先是你插入到stockid的值是空的,因为stockid没插入成功,所以列stockid出现空值,导致了INSERT失败,程序崩溃。
    由此可见主要就是因为插入stockid的值为空造成的,从这条思路找下去
    我估计可能是因为楼主设置的StockID字段类型跟你取值方式不符。可能你StockID字段是整形的,但你取值时是用float取的。
    edit1.text:=floattostr(fieldbyname('StockID').asfloat+1)
      

  8.   

    肯定是你在输入的时候有空值了,判断下
    if ***.text='' then
     showmessage('.....')
      

  9.   

    楼主照着提示去处理问题就可以了,就是StockID为空啦
    做个判断当为空是改为0