增加、删除、修改 程序代码

增加、删除、修改 程序代码

ID:42590640

大小:44.50 KB

页数:4页

时间:2019-09-18

增加、删除、修改 程序代码_第1页
增加、删除、修改 程序代码_第2页
增加、删除、修改 程序代码_第3页
增加、删除、修改 程序代码_第4页
资源描述:

《增加、删除、修改 程序代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、增加、删除、修改程序代码privatevoidbutton1_Click(objectsender,EventArgse){//创建Connection对象stringstrcon=@"DataSource=LENOVO-87EFEB86SQLEXPRESS;InitialCatalog=companyinfo;IntegratedSecurity=True";SqlConnectioncon=newSqlConnection(strcon);//添加新数据的SQL语句stringsql="inser

2、tintoemployeevalues('"+this.textBox1.Text.Trim()+"','"+this.textBox2.Text.Trim()+"','"+Convert.ToDateTime(this.textBox3.Text.Trim())+"','"+Convert.ToDateTime(this.textBox4.Text.Trim())+"','"+this.textBox5.Text.Trim()+"',"+Convert.ToDecimal(this.textBox6.

3、Text.Trim())+")";////sql语句的另一种写法////stringsql=string.Format("insertintoemployeevalues('{0}','{1}',{2},'{3}')",this.txtName.Text,this.cboSex.Text,Convert.ToInt32(this.txAge.Text),this.cboClass.Text);//创建Command对象SqlCommandcomm=newSqlCommand(sql,con);try{/

4、/打开连接con.Open();//执行插入操作if(comm.ExecuteNonQuery()>0){MessageBox.Show("添加成功");//启用id的文本框//this.txtId.Enabled=true;//this.btnDelete.Enabled=true;//this.btnModify.Enabled=true;//this.txAge.Text="";//this.txtName.Text="";}elseMessageBox.Show("添加失败");}catch(E

5、xceptionex){MessageBox.Show(ex.Message);}finally{con.Close();//关闭连接}}privatevoidbutton2_Click(objectsender,EventArgse){//创建Connection对象stringstrcon=@"DataSource=LENOVO-87EFEB86SQLEXPRESS;InitialCatalog=companyinfo;IntegratedSecurity=True";SqlConnectionc

6、on=newSqlConnection(strcon);//添加新数据的SQL语句stringsql="deleteemployeewhere姓名='"+textBox1.Text.Trim()+"'";////sql语句的另一种写法////stringsql=string.Format("insertintoemployeevalues('{0}','{1}',{2},'{3}')",this.txtName.Text,this.cboSex.Text,Convert.ToInt32(this.txA

7、ge.Text),this.cboClass.Text);//创建Command对象SqlCommandcomm=newSqlCommand(sql,con);try{//打开连接con.Open();//执行插入操作if(comm.ExecuteNonQuery()>0){MessageBox.Show("添加成功");//启用id的文本框//this.txtId.Enabled=true;//this.btnDelete.Enabled=true;//this.btnModify.Enabled=t

8、rue;//this.txAge.Text="";//this.txtName.Text="";}elseMessageBox.Show("添加失败");}catch(Exceptionex){MessageBox.Show(ex.Message);}finally{con.Close();//关闭连接}}privatevoidbutton3_Click(objectsender,EventArgse){////创建Connection对象

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。