在添加框里面录入一些数据,但是属性列并不全,想,让未录入数据的属性列为空,怎么办?
下面是我的语句
在CUSTOMERINFO表中有属性列 cname cphonenum ccity cadr csalequantity cclosedloan cloan cdiscount
protected void btnAdd_Click(object sender, EventArgs e)
    {
        string cname = txtCustomerName.Text;
        string cphonenum = txtcphonenum.Text;
        string ccity = txtccity.Text;
        string cadr = txtcadr.Text;
        string cdiscount = txtcdiscount.Text;
        string sql = "insert into customerinfo values('" + cname + "','" + cphonenum + "','" + ccity + "','" + cadr + "','" + cdiscount + "')";
        if (dataOperate.execSQL(sql))
        {
            RegisterStartupScript("", "<script>alert('添加成功!');window.opener.location.href=window.opener.location='customerInfo.aspx';window.close();</script>");
        }
        else
        {
            RegisterStartupScript("", "<script>alert('设置失败!')</script>");
        }

解决方案 »

  1.   

    string sql = "insert into customerinfo(列名1,列名2,列名3,列名4,列名5) values('" + cname + "','" + cphonenum + "','" + ccity + "','" + cadr + "','" + cdiscount + "')";
      

  2.   

    既然是程序就用判断.
    if txtCustomerName.Text = "" then
       cname = ""
    else
       cname = txtCustomerName.Text...
      

  3.   

    string cname = txtCustomerName.Text;
    if (cname==null or cname=='') 
    cname="null";
    else
    cname="'"+cname+"'"string cphonenum = txtcphonenum.Text;
    if (cphonenum ==null or cphonenum =='') 
    cphonenum ="null";
    else
    cphonenum ="'"+cphonenum +"'"string ccity = txtccity.Text;
    if (ccity ==null or ccity =='') 
    ccity ="null";
    else
    ccity ="'"+ccity +"'"string cadr = txtcadr.Text;
    if (cadr ==null or cadr =='') 
    cadr ="null";
    else
    cadr ="'"+cadr +"'"string cdiscount = txtcdiscount.Text;
    if (cdiscount ==null or cdiscount =='') 
    cdiscount ="null";
    else
    cdiscount ="'"+cdiscount +"'"string sql = "insert into customerinfo values(" + cname + "," + cphonenum + "," + ccity + "," + cadr + "," + cdiscount + ")";