SqlDataAdapter sda = sqlclass.sqlsda("select * from USERINFO where BADGENUMBER=" + this.txtEmployeeID.Text);
DataSet ds = new DataSet();
SqlCommandBuilder sb = new SqlCommandBuilder(sda);
sda.Fill(ds, "USERINFO");
ds.Tables["USERINFO"].Rows[0]["Name"] = this.txtEmployeeName.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["GENDER"] = this.cbbEmployeeSex.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["Marriage"] = this.cbbEmployeeMarriage.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["MINZU"] = this.cbbEmployeeFolk.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["政治面目"] = this.cbbEmployeePoliticsVisage.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["籍贯"] = this.txtEmployeeNativePlace.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["户口"] = this.txtEmployeehk.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["SSN"] = this.txtEmployeeIDcard.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["FPHONE"] = this.txtEmployeeTel.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["STREET"] = this.txtEmployeeAddress.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["PAGER"] = this.txtEmployeeMobileTel.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["文化程度"] = this.txtEmployeeKultuLevel.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["毕业院校"] = this.txtEmployeeCollege.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["专业"] = this.txtEmployeeSpeciality.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["部门"] = this.cbbEmployeeDept.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["TITLE"] = this.cbbEmployeeDutyType.Text.ToString();
if (this.txtEmployeeBasePay.Text!="")
{
ds.Tables["USERINFO"].Rows[0]["BasePay"] = this.txtEmployeeBasePay.Text.ToString();
}
else
{
ds.Tables["USERINFO"].Rows[0]["BasePay"] = 0.0;
}
ds.Tables["USERINFO"].Rows[0]["HIREDDAY"] = this.dtpBookInTime.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["LongSuit"] = this.txtEmployeeLongSuit.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["备注"] = this.txtEmployeeResume.Text.ToString();
ds.Tables["USERINFO"].Rows[0]["DEFAULTDEPTID"] = 1;
sda.Update(ds, "USERINFO");
ds.Dispose();
string strData = "BADGENUMBER";
ds = personnel.personalSearch(strData, this.txtEmployeeID.Text);
dgvPersonnelManage.DataSource = ds.Tables["USERINFO"];
dgvPersonnelManage.Rows[0].Selected = true;
dgvPersonnelManage.RowHeadersVisible = false;
MessageBox.Show("数据修改成功!");
同意上案例:
SqlDataAdapter sda = sqlclass.sqlsda("select * from USERINFO_lz where BADGENUMBER=" + this.txtEmployeeID.Text);
// SqlDataAdapter sda = sqlclass.sqlsda("select * from USERINFO");
DataSet ds = new DataSet();
SqlCommandBuilder sb = new SqlCommandBuilder(sda);
sda.Fill(ds, "USERINFO_lz");
DataRow newrow = ds.Tables["USERINFO_lz"].NewRow();
newrow["BADGENUMBER"] = this.txtEmployeeID.Text.ToString();
newrow["Name"] = this.txtEmployeeName.Text.ToString();
newrow["GENDER"] = this.cbbEmployeeSex.Text.ToString();
newrow["Marriage"] = this.cbbEmployeeMarriage.Text.ToString();
newrow["MINZU"] = this.cbbEmployeeFolk.Text.ToString();
newrow["政治面目"] = this.cbbEmployeePoliticsVisage.Text.ToString();
newrow["STREET"] = this.txtEmployeeNativePlace.Text.ToString();
newrow["户口"] = this.txtEmployeehk.Text.ToString();
newrow["SSN"] = this.txtEmployeeIDcard.Text.ToString();
newrow["FPHONE"] = this.txtEmployeeTel.Text.ToString();
newrow["家庭地址"] = this.txtEmployeeAddress.Text.ToString();
newrow["PAGER"] = this.txtEmployeeMobileTel.Text.ToString();
newrow["文化程度"] = this.txtEmployeeKultuLevel.Text.ToString();
newrow["毕业院校"] = this.txtEmployeeCollege.Text.ToString();
newrow["专业"] = this.txtEmployeeSpeciality.Text.ToString();
newrow["部门"] = this.cbbEmployeeDept.Text.ToString();
newrow["TITLE"] = this.cbbEmployeeDutyType.Text.ToString();
if (this.txtEmployeeBasePay.Text != "")
{
newrow["BasePay"] = this.txtEmployeeBasePay.Text.ToString();
}
else
{
newrow["BasePay"] = 0.0;
}
newrow["HIREDDAY"] = this.dtpBookInTime.Text.ToString();
newrow["LongSuit"] = this.txtEmployeeLongSuit.Text.ToString();
newrow["离职原因"] = this.txtlz.Text.ToString();
newrow["备注"] = this.txtEmployeeResume.Text.ToString();
newrow["离职日期"] = System.DateTime.Today;
newrow["考勤号码"] = this.kqh.Text;
ds.Tables["USERINFO_lz"].Rows.Add(newrow);
sda.Update(ds, "USERINFO_lz");
ds.Dispose();
MessageBox.Show("数据已经调离本数据库!");
案例2
定义相关字段:
SqlDataAdapter mydataAdapter = new SqlDataAdapter();
public struct data_ds
{
public DataSet ds ;
}
data_ds ds_qj;
打开数据库:
SqlConnection mycn = sql_cn.SqlConBind_kc();
string strSQL = "select * from 工价表 where 合同号='" + hth_id + "' and 车间组='" + str_cjz + "'order by 工序号";
SqlCommand mycmd = new SqlCommand();
mycmd.CommandType = CommandType.Text;
mycmd.CommandText = strSQL;
mycmd.Connection = mycn;
mydataAdapter.SelectCommand = mycmd;
DataSet ds = new DataSet();
mydataAdapter.Fill(ds, "工价表");
dgv_ie.AutoGenerateColumns = false;
dgv_ie.DataSource = ds;
ds_qj.ds = ds; ’此处为数据结构
dgv_ie.DataMember = "工价表";
保存的另外一种方法:
private void button3_Click(object sender, EventArgs e)
{
try
{
if (ds_qj.ds.HasChanges())
{
DataSet dschange = ds_qj.ds.GetChanges();
SqlCommandBuilder cuscb = new SqlCommandBuilder(mydataAdapter);
mydataAdapter.Update(dschange, "工价表");
MessageBox.Show("保存成功!");
dakai(keyword.Text.Trim(), cjz_id);
}
}
catch
{
MessageBox.Show("您的输入有问题!请核查");
}
}