insert into aa (feiyong)
values('"+this.textbox1.text+"')
 我这块
this.textbox1.text为空时就出错了
用if 判断的话,如果插入列多的话会很复杂.求救??谢谢

解决方案 »

  1.   

    可以写一个方法
    public string GetString(TextBox tb)
    {
        if(tb.Text.Trim()=="")
        {
            return "";
        }
        else
        {
            return tb.Text;
        }
    }
    在调用的时候就写insert into aa (feiyong) 
    values('"+GetString(this.textbox1)+"') 
      

  2.   

    这个,要不就数据库字段让它可以为空,要是必填栏位
    那就要判断了,要是不想判断,就用SQL里的函数
    string test = this.textbox1.text;
    NVL2(expr1, expr2, expr3)->expr1不为NULL,返回expr2;为NULL,返回expr3。expr2和expr3类型不同的话,expr3会转换为expr2的类型 
    你可以把expr1,expr2换成test,expr3换成0
      

  3.   

    用 condition ? first_expression : second_expression;