private void btnUpdate_Click(object sender, System.EventArgs e)
{
DataRow[] rr=dt.Select("","",DataViewRowState.ModifiedCurrent);
if(rr==null || rr.Length<=0)
{
MessageBox.Show("没有需要更改的数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
SqlConnection con=new SqlCon(Main.constr).GetCon();
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="update 档案 set [ID]=@newid,[学号]=@new学号,[姓名]=@new姓名,[性别]=@new性别,[出生日期]=@new出生日期,[籍贯]=@new籍贯,[政治面貌]=@new政治面貌,[民族]=@new民族,[毕业时间]=@new毕业时间,[就业情况]=@new就业情况,[就业单位]=@new就业单位 where [ID]=@oldid and [学号]=@old学号 and [姓名]=@old姓名 and [性别]=@old性别 and [出生日期]=@old出生日期 and [籍贯]=@old籍贯 and [政治面貌]=@old政治面貌 and [民族]=@old民族 and [毕业时间]=@old毕业时间 and [就业情况]=@old就业情况 and [就业单位]=@old就业单位";
cmd.Parameters.Add("@newid",SqlDbType.Char ,50,"ID");
cmd.Parameters.Add("@new学号",SqlDbType.Char ,50,"学号");
cmd.Parameters.Add("@new姓名",SqlDbType.Char,50,"姓名");
cmd.Parameters.Add("@new性别",SqlDbType.Char,2,"性别");
cmd.Parameters.Add("@new出生日期",SqlDbType.Char,10,"出生日期");
cmd.Parameters.Add("@new籍贯",SqlDbType.Char,20,"籍贯");
cmd.Parameters.Add("@new政治面貌",SqlDbType.Char,50,"政治面貌");
cmd.Parameters.Add("@new民族",SqlDbType.Char,2,"民族");
cmd.Parameters.Add("@new毕业时间",SqlDbType.Char,100,"毕业时间");
cmd.Parameters.Add("@new就业情况",SqlDbType.Char,2,"就业情况");
cmd.Parameters.Add("@new就业单位",SqlDbType.Char,100,"就业单位");
SqlParameter para=cmd.Parameters.Add("@oldid",SqlDbType.Char,50,"ID");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old学号",SqlDbType.Char,50,"学号");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old姓名",SqlDbType.Char,50,"姓名");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old性别",SqlDbType.Char,2,"性别");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old出生日期",SqlDbType.Char,10,"出生日期");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old籍贯",SqlDbType.Char,20,"籍贯");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old政治面貌",SqlDbType.Char,50,"政治面貌");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old民族",SqlDbType.Char,2,"民族");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old毕业时间",SqlDbType.Char,100,"毕业时间");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old就业情况",SqlDbType.Char,2,"就业情况");
para.SourceVersion=DataRowVersion.Original;
para=cmd.Parameters.Add("@old就业单位",SqlDbType.Char,100,"就业单位");
para.SourceVersion=DataRowVersion.Original;
SqlDataAdapter da=new SqlDataAdapter();
da.UpdateCommand=cmd;
try
{
da.Update(dt.Select("","",DataViewRowState.ModifiedCurrent));
}
catch(SqlException er)
{
MessageBox.Show(er.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
MessageBox.Show("已成功修改数据!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
还是出问题啊