问题描述
我已经设置了主键了,而且是自增的保证唯一,程序里面也再次设置了一次如:DataColumn[]dcs={dt.Columns["ID"]};dt.PrimaryKey=dcs;但是,TM就是出错啊出错,那个“对于不返回任何键列信息的SelectCommand,不支持UpdateCommand的动态SQL生成。”错误不散就是不散,我不想去写SQL那句了,不是懒,就是拼凑的方法真心太low了,还要考虑那么多IF,不如Dataset那句dt.updata();来得直接啊stringSQL_Refresh="select*from报名表whereID='"+ID.ToString()+"'";SqlCommandcmd=newSqlCommand(SQL_Refresh,cnn);DataSetData_all=newDataSet();SqlDataAdapteradp=newSqlDataAdapter(cmd);SqlCommandBuilderscb=newSqlCommandBuilder(adp);adp.Fill(Data_all,"报名表");DataTabledt=Data_all.Tables["报名表"];if(Data_all==null){return;}DataColumn[]dcs={dt.Columns["ID"]};dt.PrimaryKey=dcs;DataRow[]drs=dt.Select("ID="+ID.ToString());DataRowdr=drs[0];dr.BeginEdit();if(StudentName.Text!=_StudentName){dr["姓名"]=StudentName.Text;for(inti=0;i<4;i++){if(File.Exists(path_Pre+S[i]+".tif")){ComputerMyComputer=newComputer();MyComputer.FileSystem.RenameFile(path_Pre+S[i]+".tif",path_Real+S[i]+".tif");}}}dr["性别"]=Sex.Text;dr["出生日期"]=BornDate.Text;dr["户籍性质"]=Citizenkind.Text;dr["民族"]=Nation.Text;dr["毕业学校"]=School.Text;if(DetailSite.Text!=""){dr["行政区划代码"]=SiteCode;dr["联系地址"]=FullSite.Substring(Province.Text.Length+Shiji.Text.Length);dr["完全详细地址"]=FullSite;dr["证件号码"]=Identify.Text;dr["省级名称"]=Province.Text;dr["地州级名称"]=Shiji.Text;dr["县级名称"]=Town.Text;}dr["家长电话"]=ParentsPhone.Text;if(Selfphone.Text!=""){dr["学生电话"]=Selfphone.Text;}dr["家长姓名"]=Parents.Text;dr["所报专业代码"]=Major.Text;//dr["报名时间"]=dateTimePicker1.Text;dr["书费"]=Bookcost.Text;dr["生活费"]=livecost.Text;if(File.Exists(paths_fore+paths_or+"_sfz_A.tif")){dr["有无身份证正面"]="1";}else{dr["有无身份证正面"]="0";}if(File.Exists(paths_fore+paths_or+"_sfz_B.tif")){dr["有无身份证背面"]="1";}else{dr["有无身份证背面"]="0";}if(File.Exists(paths_fore+paths_or+"_hk_A.tif")){dr["有无户口首页"]="1";}else{dr["有无户口首页"]="0";}if(File.Exists(paths_fore+paths_or+"_hk_B.tif")){dr["有无户口本人页"]="1";}else{dr["有无户口本人页"]="0";}if(File.Exists(paths_fore+paths_or+"_pkzm.tif")){dr["有无贫困证明"]="1";}else{dr["有无贫困证明"]="0";}dr.EndEdit();try{adp.Update(Data_all,"报名表");Data_all.Clear();}catch(SqlExceptionexp){MessageBox.Show(exp.Message.ToString());}