我现在的DateTimePicker1绑定的是DataTable里的times列!现在我又新添加了一行数据,在点'保存'按纽的时候,总是出现错误,"无法将NULL值插入到数据库某列上",也就是DateTimePicker1的当前日期:也就是当天的日期",但是如果我选择了别的日期,就可以插入到数据库中,但就是不知道为什么,默认的当天就提醒那个错误!!!
  该控件的绑定代码是:DateTimePicker.DataBinding.Add("text",mydataset,"ds.times");保存按纽的事件是:
  SqlCommandBuild scb=new SqlCommandBuild(myDataAdapter);
    myDataAdapter.Update(myDataset,"table1");
我估计就是绑定的时候出现问题了!!但是我用DateTimePicker.DataBinding.Add("value",mydataset,"ds.times");它就不能自动添加新记录的,只是把DataGrid里默认的第一行该覆盖了!!
  哪位高手帮忙解决一下啊???谢谢 好象绑定的时候默认的今天就是空值,我如何解决啊???

解决方案 »

  1.   

    其余的地方统统不变.把插入的SQL语句改成 insert into CreditAccount(***,***,times)values(@***,@***,case @creatDate when null then getdate() else @creatDate end)就可以了。
      

  2.   

    这是我在用DateTimePicker1 添加的:
     //添加新行
                    DataRow drowadd = dtsDocEmployee.NewRow();                string strDeptCode = loadDeptCode();
                    //将数据放入新行中
                    drowadd["strEmployeeCode"] = txtDocEmployeeSetCode.Text;
                    drowadd["strEmployeeName"] = txtDocEmployeeSetName.Text;
                    drowadd["strSex"] = coBoxDocEmployeeSetSex.Text;
                    drowadd["strDeptCode"] = strDeptCode;
                    drowadd["dtEnter"] = dtDocEmployeeSetEnter.Value;
                    drowadd["strTel"] = txtDocEmployeeSetTel.Text;                drowadd["strEmployeeID"] = txtDocEmployeeSetID.Text;
                    drowadd["dtBirthday"] = dtDocEmployeeeBirth.Value;
                    drowadd["strRace"] = txtDocEmployeeSetRace.Text;
                    drowadd["strReligion"] = txDocEmployeeSetReligion.Text;
                    drowadd["strEducation"] = txtDocEmployeeSetEdu.Text;
                    drowadd["strRegisteraddress"] = txtDocEmployeeSetBorn.Text;
                    drowadd["strAddress"] = txtDocEmployeeSetAddr.Text;                //将行添加到表中
                    dtsDocEmployee.Rows.Add(drowadd);
                    //更新表
                    daEmployee.Update(dtsDocEmployee);
      

  3.   

    开始绑定DateTimePicker1 时,好象取不到数据,后来就没有绑定了!
      

  4.   

    注意:你可能犯了一个问题.非绑定列,是不可以用Cells[0].ToString();之类的方法来取得值的。你要用
    string StrId=this.DBList.DataKeys[e.Item.ItemIndex].ToString();
    string StrTitle=((TextBox)e.Item.FindControl("EditTitle")).Text.ToString().Trim();
    这样的方法来取得值。
      

  5.   

    另外,你会不会没有用if(!Page.IsPostBack)?
      

  6.   

    最好是你改一下SQL语句,这个最方便。
    insert into CreditAccount(***,***,times)values(@***,@***,isnull(@creatDate,getdate())
    可能这个语句,你更习惯点。
      

  7.   

    我的mydataset.Update();
    这个是自动生成语句的!!!我根本就没用到插入语句!!!
      

  8.   

    自动生成的语句,也是自动生成SQL的。
      

  9.   

    SqlCommandBuild scb=new SqlCommandBuild();
    这个是重构语句!!可以自动生成代码的!!
      

  10.   

    你要通过控制一个SQL语句来控制重构的其他语句。
      

  11.   

    我现在的sql语句就是一个select....没有别的!!因为我得先查出记录!!