id字段自增,标识增量和种子1;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace mpmng
{public partial class Form1 : Form{string MyConn = "server=localhost;uid=sa;pwd=xx123xx;database=dxp;";SqlConnection MyConnection = null;DataSet ds1 = new DataSet();public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){SqlConnection MyConnection = new SqlConnection(MyConn);SqlCommand MyCommand = new SqlCommand("SELECT * FROM view_emp", MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];dataGridView1.Columns[0].Width /= 3;comboBox1.Items.Add("男");comboBox1.Items.Add("女");comboBox1.Text = "";SqlCommand MyCommand2 = new SqlCommand("SELECT distinct 部门 FROM view_emp", MyConnection);SqlDataAdapter SelectAdapter2 = new SqlDataAdapter();SelectAdapter2.SelectCommand = MyCommand2;DataSet ds2 = new DataSet();SelectAdapter2.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter2.Fill(ds2);for(int i=0;i<ds2.Tables[0].Rows.Count;i++){comboBox2.Items.Add(ds2.Tables[0].Rows[i][0].ToString());}}private void button1_Click(object sender, EventArgs e)//姓名查询{SqlConnection MyConnection = new SqlConnection(MyConn);string sql1 = "SELECT * FROM view_emp where 姓名 like '%" + textBox1.Text + "%'";SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}private void 添加ToolStripMenuItem_Click(object sender, EventArgs e){Form2 f2 = new mpmng.Form2();f2.ShowDialog();}private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){SqlConnection MyConnection = new SqlConnection(MyConn);string sql1 = "SELECT * FROM view_emp where 性别 = '" + comboBox1.Text + "'";SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}private void 浏览ToolStripMenuItem_Click(object sender, EventArgs e){SqlConnection MyConnection = new SqlConnection(MyConn);SqlCommand MyCommand = new SqlCommand("SELECT * FROM view_emp", MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}private void comboBox2_SelectedIndexChanged(object sender, EventArgs e){SqlConnection MyConnection = new SqlConnection(MyConn);string sql1 = "SELECT * FROM view_emp where 部门 = '" + comboBox2.Text + "'";SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}private void button2_Click(object sender, EventArgs e)//薪资大于等于{try{SqlConnection MyConnection = new SqlConnection(MyConn);string sql1 = "SELECT * FROM view_emp where 薪资 >= " + Convert.ToInt32(textBox2.Text);SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}catch (Exception ex){MessageBox.Show("人力资源管理  " + ex.Message);textBox2.Text = "";}}private void button3_Click(object sender, EventArgs e)//薪资小于等于{try{SqlConnection MyConnection = new SqlConnection(MyConn);string sql1 = "SELECT * FROM view_emp where 薪资 <= " + Convert.ToInt32(textBox3.Text);SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();SelectAdapter.Fill(ds);dataGridView1.DataSource = ds.Tables[0];}catch(Exception ex){MessageBox.Show("人力资源管理  "+ex.Message);textBox3.Text = "";}}private void 删除ToolStripMenuItem_Click(object sender, EventArgs e){if(dataGridView1.CurrentRow.Cells[0].Value.ToString() == null || dataGridView1.CurrentRow.Cells[0].Value.ToString()==""){MessageBox.Show("请选择要删除的行!","人力资源管理系统");return;}DialogResult drt = MessageBox.Show("确定删除第"+ dataGridView1.CurrentRow.Cells[0].Value.ToString()+"行吗?", "人力资源管理系统",MessageBoxButtons.YesNo);if(drt!=DialogResult.Yes){return;}try{SqlConnection MyConnection = new SqlConnection(MyConn);SqlCommand MyCommand = new SqlCommand("delete from emp where id="+ dataGridView1.CurrentRow.Cells[0].Value, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();}catch(Exception ex){MessageBox.Show(ex.Message);}}private void 更新ToolStripMenuItem_Click(object sender, EventArgs e){if (dataGridView1.CurrentCell.RowIndex < 0) { return; }Form2 f2 = new mpmng.Form2();f2.button1Text = "更新";f2.captionText = "更新人员信息";f2.objectText = Int32.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());f2.textBox1Text= dataGridView1.CurrentRow.Cells[1].Value.ToString();f2.numericUpDownvalue1 = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[2].Value.ToString());f2.textBox4Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();f2.textBox5Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();f2.textBox6Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();f2.combo1Text = dataGridView1.CurrentRow.Cells[7].Value.ToString();f2.numericUpDownvalue2 = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[8].Value.ToString());if(dataGridView1.CurrentRow.Cells[3].Value.ToString()=="男"){f2.radiobuttonvalue1 = true; f2.radiobuttonvalue2 = false;}else{f2.radiobuttonvalue1 = false; f2.radiobuttonvalue2 = true;}f2.ShowDialog();}}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace mpmng
{public partial class Form2 : Form{string MyConn = "server=localhost;uid=sa;pwd=xx123xx;database=dxp;";SqlConnection MyConnection = null;DataSet ds1 = new DataSet();private int objectid = 0;public Form2(){InitializeComponent();}private void Form2_Load(object sender, EventArgs e){comboBox1.Items.Add("群众");comboBox1.Items.Add("党员");comboBox1.Items.Add("团员");comboBox1.Text = "党员";}private void button1_Click(object sender, EventArgs e){#region 添加if (button1.Text == "添加"){if (textBox1.Text == ""){MessageBox.Show("人力资源管理,姓名不能为空!");}string name = textBox1.Text;int age = (int)numericUpDown1.Value;string sex = "男";if (radioButton1.Checked == true){sex = "男";}else{sex = "女";}string dept = textBox4.Text;string position = textBox5.Text;string prof = textBox6.Text;string poliface = comboBox1.Text;int salary = (int)numericUpDown2.Value;string sql1 = "insert into emp values ('" + name + "'," + age + ",'" + sex + "','" + dept + "','" + position + "','" + prof + "','" + poliface + "'," + salary + ")";try{SqlConnection MyConnection = new SqlConnection(MyConn);SqlCommand MyCommand = new SqlCommand(sql1, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;DataSet ds = new DataSet();MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();this.Hide();}catch (Exception ex){MessageBox.Show("人力资源管理,添加," + ex.Message);}}#endregion#region 更新if (button1.Text == "更新"){string sexstr = "男";if (radioButton1.Checked == true) { sexstr = "男"; }if (radioButton2.Checked == true) { sexstr = "女"; }string sql2 = "UPDATE emp SET name='"+textBox1.Text+"',age="+Convert.ToInt32(numericUpDown1.Value)+", sex='"+sexstr+"',dept='"+textBox4.Text+"',position='"+textBox5.Text+"',prof='"+textBox6.Text+"',poliface='"+comboBox1.Text+"',salary="+Convert.ToInt32(numericUpDown2.Value)+" WHERE id="+objectid;try{SqlConnection MyConnection = new SqlConnection(MyConn);SqlCommand MyCommand = new SqlCommand(sql2, MyConnection);SqlDataAdapter SelectAdapter = new SqlDataAdapter();SelectAdapter.SelectCommand = MyCommand;MyConnection.Open();SelectAdapter.SelectCommand.ExecuteNonQuery();MyConnection.Close();this.Hide();}catch (Exception ex){MessageBox.Show("人力资源管理,更新," + ex.Message);}}#endregion}#region 传值变量public int objectText{get { return this.objectid; }set { this.objectid = value; }}public string button1Text{get { return this.button1.Text; }set { this.button1.Text = value; }}public string captionText{get { return this.Text; }set { this.Text = value; }}public string textBox1Text{get { return this.textBox1.Text; }set { this.textBox1.Text = value; }}public string textBox4Text{get { return this.textBox4.Text; }set { this.textBox4.Text = value; }}public string textBox5Text{get { return this.textBox5.Text; }set { this.textBox5.Text = value; }}public string textBox6Text{get { return this.textBox6.Text; }set { this.textBox6.Text = value; }}public decimal numericUpDownvalue1{get { return this.numericUpDown1.Value; }set { this.numericUpDown1.Value = value; }}public bool radiobuttonvalue1{get { return this.radioButton1.Checked; }set { this.radioButton1.Checked = value; }}public bool radiobuttonvalue2{get { return this.radioButton2.Checked; }set { this.radioButton2.Checked = value; }}public string combo1Text{get { return this.comboBox1.Text; }set { this.comboBox1.Text = value; }}public decimal numericUpDownvalue2{get { return this.numericUpDown2.Value; }set { this.numericUpDown2.Value = value; }}#endregion}
}

只要把表的字段更改;代码中相应字段处更改;就能变成别的单表增删改查程序;拿去花吧;

有活可以联系我;

C# 功能完整的单表增删改查程序相关推荐

  1. MySQL基础知识-MySQL概述安装,单表增删改查,函数,约束,多表查询,事物

    MySQL基础知识-MySQL概述安装,单表增删改查,函数,约束,多表查询,事物 前言 1.MySQL概述 1.1数据库相关概念 1.2MySQL数据库 1.2.1版本 1.2.2下载 1.2.3安装 ...

  2. mybatis --入门 单表增删改查-curd

    目录 1. mybatis 环境搭建 2. 实体类映射文件配置(写sql) 3. mybatis核心配置文件 (环境配置) 4. 测试 mybatis document https://mybatis ...

  3. mysql如何修改学生表_MySQL 详细单表增删改查crud语句

    MySQL 增删改查语句 1.创建练习表 这里练习表没有满足三范式 第一范式(又称 1NF):保证每列的原子性 数据表中的每一列(字段),必须是不可拆分的最小单元,也就是确保每一列的原子性.满足第一范 ...

  4. django调用python脚本返回_Django框架(九)—— 单表增删改查,在Python脚本中调用Django环境...

    单表增删改查,在Python脚本中调用Django环境 一.数据库连接配置 如果连接的是pycharm默认的Sqlite,不用改动,使用默认配置即可 如果连接mysql,需要在配置文件中的settin ...

  5. Django框架(八)--单表增删改查,在Python脚本中调用Django环境

    一.数据库连接配置 如果连接的是pycharm默认的Sqlite,不用改动,使用默认配置即可 如果连接mysql,需要在配置文件中的setting中进行配置: 将DATABASES={} 更新为 DA ...

  6. springboot整合mybatis实现简单的单表增删改查(完整代码可下载)

    搭建项目 项目简单效果,前端效果丑的一批,主要是后端功能实现: springboot增删改查 csdn完整代码下载链接: springboot+mybatis Gitee下载地址: Gitee下载地址 ...

  7. 增删改查最终总结—2.1.1(单表-增删改查)

    一个 Mybatis 开发神器:Fast MyBatis 超好用 --------Fast Mybatis开发文档 每一个增删改查前都要先看这个--增删改查操作 都需要注意: 1.在控制层最后一行代码 ...

  8. django(七)之数据库表的单表-增删改查QuerySet,双下划线

    https://www.cnblogs.com/haiyan123/p/7738435.html https://www.cnblogs.com/yuanchenqi/articles/6083427 ...

  9. Blazor实战——Known框架单表增删改查导

    本章介绍学习增.删.改.查.导功能如何实现,下面以商品资料作为示例,该业务栏位如下: 类型.编码.名称.规格.单位.库存下限.库存上限.备注 1. 前后端共用 1.1. 创建实体类 在KIMS项目En ...

最新文章

  1. 算法原理:大数据处理的分治思想!
  2. 郑州志泽网络科技--SSH模拟试题
  3. php_mvc实现步骤五
  4. Django从理论到实战(part28)--ORM常用Field详解
  5. 程序员特有的9个坏习惯
  6. 前端学习(1765):前端调试值之性能分析的方法三
  7. python ant_('python,-ANT--编程字典',)
  8. Vue之安装vscode
  9. 链表常见操作java实现二:反转链表,从尾到头倒序遍历
  10. 软件multisim的安装教程
  11. piano+apk+android,PianOli | F-Droid - Free and Open Source Android App Repository
  12. 超大硬盘linux快速格式化,Linux系统下超大硬盘快速格式化详解
  13. 怎样快速下载Google Driver文件-使用IDM下载Google Driver文件
  14. 【解决方法(最详细)】WIN10系统使用Teamviewer远程连接时被检测出商业用途
  15. mavon-editor编辑器与图片上传
  16. numpy第三章-索引器、多级索引
  17. Java mail使用QQ邮箱发送邮件配置方案
  18. 北京市市场主体发展情况报告 (zz)
  19. Git学习笔记及一些问题(廖雪峰版)
  20. 手工搭建多层(多隐藏层)BP神经网络

热门文章

  1. Ubuntu 9.10下Nvidia官方最新190.42显卡驱动安装
  2. 高级指令——kill指令、ifconfig指令、reboot指令、shutdown指令、uptime指令、uname指令
  3. 使用ServletContext对象完成网页计数器
  4. python pyppeteer自定义chromium目录
  5. JavaScript中call()和apply()的用法及区别
  6. 有效降低传导辐射干扰的小技巧
  7. Bzoj 3680 吊打xxx【[模拟退火】
  8. [YTU]_2916(Shape系列-2)
  9. matlab apfc,APFC-Boost 带APFC的Boost升压变换器在Matlab中的仿真实现 - 下载 - 搜珍网...
  10. Visual Studio C++ 画图【极简版】