问题描述
在做学生信息系统时,add按钮是将数据批量存入dataset中,可是最后一个数据只存入了一个空值。add按钮的代码如下:privatevoidbtnAdd_Click(objectsender,EventArgse){try{DataRowrow=hRDataSet.Tables["empdetails"].NewRow();intmax=Convert.ToInt32(hRDataSet.empdetails.Compute("MAX(cEmployeeCode)","true"))+1;stringa=max.ToString();if(a.Length<6){for(inti=0;i<(9-a.Length);i++){a=a.Insert(0,"0");}}txtCode.Text=a;row["cEmployeeCode"]=txtCode.Text.ToString();txtName.Text="";txtAddress.Text="";txtState.Text="";txtCountry.Text="";cbDesignation.Text="";cbDepartment.Text="";row["EmployeeName"]=txtName.Text.ToString();row["vAddress"]=txtAddress.Text.ToString();row["cState"]=txtState.Text.ToString();row["cCountry"]=txtCountry.Text.ToString();row["cDesignation"]=cbDesignation.Text.Trim();row["vDepartmentName"]=cbDepartment.Text.Trim();hRDataSet.Tables["empdetails"].Rows.Add(row);}catch(Exceptionex){MessageBox.Show(ex.Message);}}
点一次add添加一条数据。save按钮将dataset更新到数据库。可是我最后一条add数据添加为空
解决方案
解决方案二:
你自己赋了个空字符串,能添加什么
解决方案三:
txtName.Text="";txtAddress.Text="";txtState.Text="";txtCountry.Text="";cbDesignation.Text="";cbDepartment.Text="";都是空值,如果是初始化,不要放这里面
解决方案四:
谁能教我在add按钮中怎么改啊,我知道错误的原因,但不会改
解决方案五:
换个位置试试catch(Exceptionex){MessageBox.Show(ex.Message);}txtName.Text="";txtAddress.Text="";txtState.Text="";txtCountry.Text="";cbDesignation.Text="";cbDepartment.Text="";
解决方案六:
引用4楼u011822950的回复:
换个位置试试catch(Exceptionex){MessageBox.Show(ex.Message);}txtName.Text="";txtAddress.Text="";txtState.Text="";txtCountry.Text="";cbDesignation.Text="";cbDepartment.Text="";
这样会自动将第一条数据填充进去,不需要我输入了。
解决方案七:
该回复于2014-11-24 16:04:29被版主删除