我有一个员工信息录入的界面,在点击“添加”后,我希望员工号如p001自动生成,请问应该怎么做?
我现在的员工号是和其它值一样,手动输入的。我声明了一个DataSet,把Employee表放入DatasetEmployee,然后在页面登录时,用da.Fill填充(this.DataSetEmployy,"Employee"),然后将DatasetEmployee和datagrid邦定,接下来将每个控件和DataSetEmployy里的列值邦定,那我现在要改员工号,请问应该怎么改呢?
我刚学,不是很懂,哪位大人帮小妹一下好吗,写的详细一点,我怕我不能理解,感激涕零T_T
public EmployeeManage()
{
InitializeComponent();//窗体自带的所有控件的构造函数
this.connectionStr="workstation id=localhost;Integrated Security=SSPI;database=Management";
this.selectStr="select * from Employee";
this.myConnection=new SqlConnection(connectionStr);
this.da1=new SqlDataAdapter(this.selectStr,this.myConnection);
//创建数据适配器
this.Command1=new SqlCommand();
this.Command1.Connection=this.myConnection;
}
private void EmployeeManage_Load(object sender, System.EventArgs e)
{
try
{
this.myConnection.Open();
this.da1.Fill(this.DataSetEmployy,"Employee");
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.myConnection.Close();
}
this.DataSet_Bingding();
}
private void DataSet_Bingding()//手动绑定,把数据集中的数据绑定到数据控件中
{
this.dg1_Employee.DataSource=this.DataSetEmployy;
this.dg1_Employee.DataMember="Employee";
this.textEmployeeID.DataBindings.Add("Text",this.DataSetEmployy,"Employee.EmployeeID");
this.textName.DataBindings.Add("Text",this.DataSetEmployy,"Employee.EmployeeName");
this.comboSex.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Sex");
this.numericUpDown1.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Age");
this.comboDepartment.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Department");
this.comboTitle.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Title");
this.comboDuty.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Duty");
this.comboWorkType.DataBindings.Add("Text",this.DataSetEmployy,"Employee.WorkType");
this.comboDegree.DataBindings.Add("Text",this.DataSetEmployy,"Employee.Degree");
this.dateTimePicker1.DataBindings.Add("Text",this.DataSetEmployy,"Employee.InDate");
}
private void btnAdd_Click(object sender, System.EventArgs e)//添加
{
this.BindingContext[this.DataSetEmployy,"Employee"].AddNew();//在数据集中添加一行新的记录
}