zoukankan      html  css  js  c++  java
  • C#最基本的数据库增删改查

    namespace access
    {
        public partial class Form1 : Form
        {
            //定义数据库的连接路径
            string txtConn ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\access.mdb";
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                //修改记录按钮代码
                using(OleDbConnection conn = new OleDbConnection(txtConn))
                {
                    string sql = string.Format("update table1 set fl='{1}',lxfs='{2}',dzyj='{3}' where xm='{0}'", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
                    OleDbCommand cmd = new OleDbCommand(sql, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            private void button2_Click(object sender, EventArgs e)
            {
                //删除记录按钮代码
                using (OleDbConnection conn = new OleDbConnection(txtConn))
                {
                    string sql = string.Format("delete from table1 where xm='{0}'", textBox1.Text);
                    OleDbCommand cmd = new OleDbCommand(sql, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            private void button3_Click(object sender, EventArgs e)
            {
                //添加记录按钮代码
                using (OleDbConnection conn = new OleDbConnection(txtConn))
                {
                    string sql = string.Format("insert into table1(xm,fl,lxfs,dzyj) values('{0}','{1}','{2}','{3}')", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
                    OleDbCommand cmd = new OleDbCommand(sql, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
           
        }
    }
  • 相关阅读:
    Git常用命令
    更新CentOS内核
    VMware虚拟机安装Ubuntu系统步骤详解
    Ubuntu安装遇到的问题
    IOT OS and OTA
    gcc c asm,C程序内嵌汇编
    makefile and make tips
    RTEMS目录梳理Sparc
    关于FreeRTOS的信号量、队列
    FreeRTOS任务源码分析以及程序堆栈与任务堆栈的关系
  • 原文地址:https://www.cnblogs.com/wzwyc/p/6292670.html
Copyright © 2011-2022 走看看