string sql1 ="insert into tb_product(id,sys_create_stuff,sys_create_date,sys_modify_stuff,sys_modify_date,sys_delete_flag,sys_remote,ASACode,WordCode_1,WordCode_2,WordCode_3,WordCode_4,BrandColor,WordPrice,Origin,Material,Brand,ProductName)values(NEWID(),'9E3941AE-84F3-4983-940E-0F36B609CB4B',GETDATE(),'9E3941AE-84F3-4983-940E-0F36B609CB4B',GETDATE(),'0','0','" 
                    + objDS.Tables[0].Rows[i][2].ToString() + "', '" + a + "' ,'" + b + "','" + c + "','" + d + 
                    "',(select id from tb_product where BrandColor=(select id from zl_color where colorName='" 
                    + objDS.Tables[0].Rows[i][7].ToString() + "')),
                 '"+Convert.ToDecimal(objDS.Tables[0].Rows[i][8].ToString())+"',//此处中含有空值,我想问问有没有什么方法可以判断一下如果是空值则数据库里存空值,如果有和转化为decimal存到数据库中
(select id from tb_product where Origin=(select id from zl_country where Name='"
                    + objDS.Tables[0].Rows[i][10].ToString() + "')),(select id from tb_product where Material=(select id from zl_material where MaterialName= '" 
                    + objDS.Tables[0].Rows[i][11].ToString() + "')),(select id from tb_product where Brand=(select id from zl_brand where BrandName='" 
                    + objDS.Tables[0].Rows[i][5].ToString() + "')),'" + objDS.Tables[0].Rows[i][4].ToString() + "')";

解决方案 »

  1.   

    string.IsNullOrEmpty(objDS.Tables[0].Rows[i][8].ToString())?"":Convert.ToDecimal(objDS.Tables[0].Rows[i][8].ToString())
      

  2.   

    Convert.ToDecimal(objDS.Tables[0].Rows[i][8].ToString())+"',//此处中含有空值,我想问问有没有什么方法可以判断一下如果是空值则数据库里存空值,如果有和转化为decimal存到数据库中
    --> 
    先做空置判断,String x;
    x=(objDS.Tables[0].Rows[i][8]!=System.DBNull.Value?objDS.Tables[0].Rows[i][8].ToString():"null");然后把x拼接到sql1中.
      

  3.   

    首先你得先确认该字段允许存放空值,如果允许
    就判objDS.Tables[0].Rows[i][8] == null,是就拼个NULL进去,不是就转换objDS.Tables[0].Rows[i][8]
      

  4.   

    但是string e = objDS.Tables[0].Rows[i][8].ToString();
                        string f = string.Empty;
                        if (e !=null )
                        {
                            
                            f= Convert.ToDecimal(objDS.Tables[0].Rows[i][8].ToString());//此处报错,错误1无法将类型“decimal”隐式转换为“string”                     
                        }
                        else
                        {
                             
                            
                        }
    这咋整啊?拜托了
      

  5.   

    没必要转换为Decimal,因为此处是拼接在字符串sql1中用的,直接用字符串即可.
    请参考2楼写法.
      

  6.   

    亲,我数据库表里的那列的属性是Decimal类型的,我也不想转换成这个啊。
      

  7.   

    因为此处是拼接在字符串sql1中用的,直接用objDS.Tables[0].Rows[i][8].ToString()字符串去拼接就可以了.