C#常用增删改查源码_第1页
C#常用增删改查源码_第2页
C#常用增删改查源码_第3页
C#常用增删改查源码_第4页
C#常用增删改查源码_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

-.z.这个是添加的代码usingSystem;usingSystem.Collections.Generic;usingSystem.ponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Te*t;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace学生成绩管理系统{publicpartialclassstudentluru:Form{//CurrencyManagercmAmend;//SqlConnectionsqlConnection1=newSqlConnection();publicstudentluru(){Initializeponent();}privatevoidstudentluru_Load(objectsender,EventArgse){}//录入privatevoidbutton5_Click(objectsender,EventArgse){stringsno=te*tBo*1.Te*t;stringsname=te*tBo*2.Te*t;stringsse*=te*tBo*3.Te*t;stringsage=te*tBo*4.Te*t;stringsclass=te*tBo*5.Te*t;stringsdept=te*tBo*6.Te*t;stringsaddress=te*tBo*7.Te*t;stringsphone=te*tBo*8.Te*t;stringsqq=te*tBo*9.Te*t;if(te*tBo*1.Te*t==""||te*tBo*2.Te*t==""||te*tBo*5.Te*t==""){if(te*tBo*1.Te*t==""){MessageBo*.Show("**不能为空","警告提示",MessageBo*Buttons.OKCancel,MessageBo*Icon.Error);te*tBo*1.Focus();return;}if(te*tBo*2.Te*t==""){MessageBo*.Show("不能为空","警告提示",MessageBo*Buttons.OKCancel,MessageBo*Icon.Error);te*tBo*2.Focus();return;}if(te*tBo*5.Te*t==""){MessageBo*.Show("班级不能为空","警告提示",MessageBo*Buttons.OKCancel,MessageBo*Icon.Error);te*tBo*5.Focus();return;}}else{stringconnstr="server=IT32;uid=sa;pwd='sa';database=sc;";try{SqlConnectionconn=newSqlConnection(connstr);conn.Open();stringsqlinsert="insertintostudentinfovalues('"+sno+"','"+sname+"','"+sse*+"','"+sage+"','"+sclass+"','"+sdept+"','"+saddress+"','"+sphone+"','"+sqq+"')";Sqlmandsc=newSqlmand(sqlinsert,conn);sc.E*ecuteNonQuery();te*tBo*1.Te*t="";te*tBo*2.Te*t="";te*tBo*3.Te*t="";te*tBo*4.Te*t="";te*tBo*5.Te*t="";te*tBo*6.Te*t="";te*tBo*7.Te*t="";te*tBo*8.Te*t="";te*tBo*9.Te*t="";MessageBo*.Show("数据已经添加成功","温馨提示");conn.Close();}catch(E*ceptione*){MessageBo*.Show(e*.ToString());}}}privatevoidbutton8_Click(objectsender,EventArgse){this.Dispose();}}}这个是查询界面的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Te*t;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace学生成绩管理系统{publicpartialclassstudentcha*un:Form{DataTabledt=newDataTable();stringper;stringsno;CurrencyManagercmAmend;publicstudentcha*un(){Initializeponent();}publicstudentcha*un(stringk,strings){Initializeponent();per=k;sno=s;}privatevoidstudentcha*un_Load(objectsender,EventArgse){//TODO:这行代码将数据加载到表“studentDataSet.studentinfo”中。您可以根据需要移动或移除它。//this.studentinfoTableAdapter.Fill(this.studentDataSet.studentinfo);//数据绑定if(per=="超级用户"){stringsqlsel="select*fromstudentinfo";DataTabledt=bangding(sqlsel);cmAmend=(CurrencyManager)BindingConte*t[dt];this.dataGridView1.DataSource=dt;this.boBo*1.DataSource=dt;this.boBo*1.DisplayMember="sno";this.boBo*2.DataSource=dt;this.boBo*2.DisplayMember="sname";}if(per=="普通用户"){stringsqlsel="select*fromstudentinfowheresno='"+sno+"'";DataTabledt=bangding(sqlsel);cmAmend=(CurrencyManager)BindingConte*t[dt];this.dataGridView1.DataSource=dt;this.boBo*1.DataSource=dt;this.boBo*1.DisplayMember="sno";this.boBo*2.Enabled=false;this.radioButton2.Enabled=false;//this.toolStripButton1.Enabled=false;//this.toolStripButton2.Enabled=false;//this.toolStripButton3.Enabled=false;//this.toolStripButton4.Enabled=false;//this.boBo*2.DataSource=dt;//this.boBo*2.DisplayMember="sname";}}DataTablebangding(stringsqlsel){stringconnstr="server=.;uid=sa;pwd=sa;database=sc";using(SqlConnectionconn=newSqlConnection(connstr)){conn.Open();DataSetds=newDataSet();SqlDataAdapterda=newSqlDataAdapter(sqlsel,conn);da.Fill(ds,"coust");DataTabledt=ds.Tables["coust"];conn.Close();returndt;}}privatevoidbutton1_Click(objectsender,EventArgse){if(this.radioButton1.Checked==true){string*uehao=boBo*1.Te*t;stringsqlsel="select*fromstudentinfowheresno='"+*uehao+"'";this.dataGridView1.DataSource=bangding(sqlsel);}else{string*ingming=boBo*2.Te*t;stringsqlsel="select*fromstudentinfowheresname='"+*ingming+"'";this.dataGridView1.DataSource=bangding(sqlsel);}}privatevoidradioButton1_CheckedChanged(objectsender,EventArgse){if(this.radioButton1.Checked==true){this.boBo*1.Enabled=true;this.boBo*2.Enabled=false;}else{this.boBo*1.Enabled=false;this.boBo*2.Enabled=true;}}privatevoidcheckstate(intpos){if(pos==0){toolStripButton1.Enabled=false;toolStripButton2.Enabled=false;toolStripButton3.Enabled=true;toolStripButton4.Enabled=true;}else{toolStripButton1.Enabled=true;toolStripButton2.Enabled=true;toolStripButton3.Enabled=true;toolStripButton4.Enabled=true;}}//首记录privatevoidtoolStripButton1_Click(objectsender,EventArgse){cmAmend.Position=0;//设置为0.回到首记录this.dataGridView1.Select();checkstate(cmAmend.Position);}//上一条privatevoidtoolStripButton2_Click(objectsender,EventArgse){cmAmend.Position--;this.dataGridView1.Select();checkstate(cmAmend.Position);}//下一条privatevoidtoolStripButton3_Click(objectsender,EventArgse){cmAmend.Position++;this.dataGridView1.Select();checkstate(cmAmend.Position);}//末记录privatevoidtoolStripButton4_Click(objectsender,EventArgse){cmAmend.Position=cmAmend.Count-1;this.dataGridView1.Select();checkstate(cmAmend.Position);}}}删除的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Te*t;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace学生成绩管理系统{publicpartialclassstudentshanchu:Form{CurrencyManagercmAmend;publicstudentshanchu(){Initializeponent();}privatevoidstudentshanchu_Load(objectsender,EventArgse){//TODO:这行代码将数据加载到表“studentDataSet.studentinfo”中。您可以根据需要移动或移除它。//this.studentinfoTableAdapter.Fill(this.studentDataSet.studentinfo);//数据绑定stringsqlsel="select*fromstudentinfo";DataTabledt=bangding(sqlsel);cmAmend=(CurrencyManager)BindingConte*t[dt];this.dataGridView1.DataSource=dt;this.te*tBo*1.DataBindings.Add("te*t",dt,"sno");this.te*tBo*2.DataBindings.Add("te*t",dt,"sname");this.te*tBo*3.DataBindings.Add("te*t",dt,"sse*");this.te*tBo*4.DataBindings.Add("te*t",dt,"sage");this.te*tBo*5.DataBindings.Add("te*t",dt,"sclass");this.te*tBo*6.DataBindings.Add("te*t",dt,"sdept");this.te*tBo*7.DataBindings.Add("te*t",dt,"saddress");this.te*tBo*8.DataBindings.Add("te*t",dt,"sphone");this.te*tBo*9.DataBindings.Add("te*t",dt,"sqq");}DataTablebangding(stringsqlsel){stringconnstr="server=.;uid=sa;pwd=sa;database=sc";using(SqlConnectionconn=newSqlConnection(connstr)){conn.Open();DataSetds=newDataSet();SqlDataAdapterda=newSqlDataAdapter(sqlsel,conn);da.Fill(ds,"coust");DataTabledt=ds.Tables["coust"];conn.Close();returndt;}}privatevoidcheckBo*1_CheckedChanged(objectsender,EventArgse){if(checkBo*1.Checked==true){this.Height=450;}else{this.Height=250;}}privatevoidbutton1_Click(objectsender,EventArgse){if(MessageBo*.Show("你确定要删除该记录吗","询问",MessageBo*Buttons.OKCancel,MessageBo*Icon.Question)==DialogResult.OK){intpos=this.dataGridView1.CurrentCell.RowInde*;//获取该行stringconnstr="server=.;uid=sa;pwd=sa;database=sc";using(SqlConnectionconn=newSqlConnection(connstr)){conn.Open();DataSetds=newDataSet();stringsqlset="select*fromstudentinfo";//数据集SqlDataAdapterda=newSqlDataAdapter(sqlset,conn);da.Fill(ds,"coust");DataTabledt=ds.Tables["coust"];SqlmandBuildercb=newSqlmandBuilder(da);dt.Rows[pos].Delete();da.Update(ds,"coust");te*tBo*1.Te*t="";te*tBo*2.Te*t="";te*tBo*3.Te*t="";te*tBo*4.Te*t="";te*tBo*5.Te*t="";te*tBo*6.Te*t="";te*tBo*7.Te*t="";te*tBo*8.Te*t="";te*tBo*9.Te*t="";this.dataGridView1.DataSource=bangding(sqlset);MessageBo*.Show("恭喜你已成功删除","温馨提示");conn.Close();}}}}}修改的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Te*t;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace学生成绩管理系统{publicpartialclassstudent*iugai:Form{stringconnstr="server=.;uid=sa;pwd=sa;database=sc";stringper;stringsno;CurrencyManagercmAmend;publicstudent*iugai(){Initializeponent();}publicstudent*iugai(stringk,strings){Initializeponent();per=k;sno=s;}privatevoidcheckBo*1_CheckedChanged(objectsender,EventArgse){if(checkBo*1.Checked==true){//this.Height=450;boBo*1.Enabled=false;te*tBo*1.Enabled=false;}else{//this.Height=250;boBo*1.Enabled=true;te*tBo*1.Enabled=true;}}privatevoidstudent*iugai_Load(objectsender,EventArgse){//数据绑定if(per=="超级用户"){stringsqlsel="select*fromstudentinfoorderbysnoasc";DataTabledt=bangding(sqlsel);cmAmend=(CurrencyManager)BindingConte*t[dt];this.boBo*1.DataSource=dt;this.boBo*1.DisplayMember="sno";this.te*tBo*1.DataBindings.Add("te*t",dt,"sname");this.te*tBo*2.DataBindings.Add("te*t",dt,"sse*");this.te*tBo*3.DataBindings.Add("te*t",dt,"sage");this.te*tBo*4.DataBindings.Add("te*t",dt,"sclass");this.te*tBo*5.DataBindings.Add("te*t",dt,"sdept");this.te*tBo*6.DataBindings.Add("te*t",dt,"saddress");this.te*tBo*7.DataBindings.Add("te*t",dt,"sphone");this.te*tBo*8.DataBindings.Add("te*t",dt,"sqq");}if(per=="普通用户"){stringsqlsel="select*fromstudentinfowheresno='"+sno+"'";DataTabledt=bangding(sqlsel);this.boBo*1.DataSource=dt;this.boBo*1.DisplayMember="sno";this.te*tBo*1.DataBindings.Add("te*t",dt,"sname");this.te*tBo*2.DataBindings.Add("te*t",dt,"sse*");this.te*tBo*3.DataBindings.Add("te*t",dt,"sage");this.te*tBo*4.DataBindings.Add("te*t",dt,"sclass");this.te*tBo*5.DataBindings.Add("te*t",dt,"sdept");this.te*tBo*6.DataBindings.Add("te*t",dt,"saddress");this.te*tBo*7.DataBindings.Add("te*t",dt,"sphone");this.te*tBo*8.DataBindings.Add("te*t",dt,"sqq");}}DataTablebangding(stringsqlsel){//stringconnstr="server=.;uid=sa;pwd=sa;database=sc";using(SqlConnectionconn=newSqlConnection(connstr)){conn.Open();DataSetds=newDataSet();SqlDataAdapterda=newSqlDataAdapter(sqlsel,conn);da.Fill(ds,"coust");DataTabledt=ds.Tables["coust"];conn.Close();returndt;}}privatevoidbutton1_Click(objectsender,EventArgse){if(checkBo*1.Checked==true){stringsno=boBo*1.Te*t;stringsname=te*tBo*1.Te*t;stringse*=te*tBo*2.Te*t;stringage=te*tBo*3.Te*t;stringsclass=te*tBo*4.Te*t;stringsdept=te*tBo*5.Te*t;stringsaddress=te*tBo*6.Te*t;stringsphone=te*tBo*7.Te*t;stringsqq=te*tBo*8.Te*t;if(te*tBo*2.Te*t==""||te*tBo*3.Te*t

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论