zoukankan      html  css  js  c++  java
  • 数据库简单增删改查

    namespace 数据库增删改查
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e) //登陆(查询)
            {
                string user = textBox2.Text;
                string password = textBox3.Text;
    
                SqlConnection coon = new SqlConnection("server=.;database=enter;user=sa;pwd=123"); //连接数据库
                coon.Open();//打开数据库
                SqlCommand cmd = coon.CreateCommand();//执行查询语句
                cmd.CommandText = "select * from enters where username='"+user+"' and userpass='"+password+"'"; //进行匹配
                SqlDataReader dr = cmd.ExecuteReader();//执行查询,将结果反馈给dr
                if (dr.Read())
                {
                    MessageBox.Show("登陆成功");
                }
                else
                {
                    MessageBox.Show("登陆失败");
                }
                coon.Close();
    
            }
    
            private void button3_Click(object sender, EventArgs e) //添加
            {
                string user = textBox2.Text;
                string password = textBox3.Text;
                SqlConnection coon = new SqlConnection("server=.;database=enter;user=sa;pwd=123");
                coon.Open();
                SqlCommand cmd = coon.CreateCommand();
                cmd.CommandText = "insert into enters values('"+user+"','"+password+"')";
                int count = cmd.ExecuteNonQuery();//增删改都用这个
                if(count>0)
                {
                    MessageBox.Show("添加成功");
                }
                coon.Close();
            }
    
            private void button2_Click(object sender, EventArgs e) //修改
            {
                string code = textBox1.Text;
                string user = textBox2.Text;
                string password = textBox3.Text;
                SqlConnection coon = new SqlConnection("server=.;database=enter;user=sa;pwd=123");
                coon.Open();
                SqlCommand cmd = coon.CreateCommand();
                cmd.CommandText = "update enters set username='"+user+"' , userpass='"+password+"' where code="+code;
                int count = cmd.ExecuteNonQuery();
                if(count>0)
                {
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show("修改失败!");
                }
                coon.Close();
            }
    
            private void button4_Click(object sender, EventArgs e) //删除
            {
                string code = textBox1.Text;
                SqlConnection coon = new SqlConnection("server=.;database=enter;user=sa;pwd=123");
                coon.Open();
                SqlCommand cmd = coon.CreateCommand();
                cmd.CommandText = "delete from enters where code="+code;
                cmd.ExecuteNonQuery();
                coon.Close();
            }
        }
    }
  • 相关阅读:
    可自主二次开发的微信云控客服crm系统软件(带源码)
    个人微信号二次开发sdk协议,微信个人号开发API接口
    最新的微信SCRM客服系统
    微信个人号客服系统淘宝客发单机器人sdk服务端接口列表
    sdk定制开发微信群控云控客服系统教程
    web版微信自动发消息(实现微信个人号机器人)
    Adobe Audition 基本使用
    MPEG-7 视觉描述符
    图像检索:几种基于纹理特征的图像检索算法
    div+css基础教程
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4544886.html
Copyright © 2011-2022 走看看