• 大小: 680KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: c#  sql  

资源简介

c#窗体应用程序实现数据库增删改查c#窗体应用程序实现数据库增删改查c#窗体应用程序实现数据库增删改查

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CDemo1
{
    public partial class frmadd : Form
    {
        public frmadd()
        {
            InitializeComponent();
        }

        private void frmadd_Load(object sender EventArgs e)
        {
            //this.
            this.rdonan.Checked = this.rdos1.Checked = true;
            this.cboxueli.SelectedIndex = 0;
        }

        private void button1_Click(object sender EventArgs e)
        {
            if (txtid.Text != ““ && txtname.Text != ““)
            {
                string id = txtid.Text;
                string name = this.txtname.Text;
                string sex = “男“;
                if (rdonv.Checked == true) {
                    sex = “女“;
                }
                DateTime chus = DateTime.Parse(dtpcs.Text);
                string nianji = “S1“;
                if (rdos2.Checked == true) {
                    nianji = “S2“;
                } else if (rdoy2.Checked == true) {
                    nianji = “Y2“;
                }
                string xueli = cboxueli.Text;
                string aihao = ““;
                if (ckchifan.Checked == true) {
                    aihao += “吃饭 “;
                }
                if (ckshuijiao.Checked == true) {
                    aihao += “睡觉“;
                }
                if (ckshuqian.Checked == true) {
                    aihao += “数钱“;
                }
                string str = “server=.;database=SchoolManager;uid=sa;pwd=root“;
                SqlConnection con = new SqlConnection(str);
                try
                {
                    string sql = string.Format(@“insert into dbo.Student
values(‘{0}‘‘{1}‘‘{2}‘‘{3}‘‘{4}‘‘{5}‘‘{6}‘)“ id name sex chus xueli nianji aihao);
                    SqlCommand cmd = new SqlCommand(sql con);
                    con.Open();
                    int addfh = cmd.ExecuteNonQuery();
                    if (addfh > 0)
                    {
                        MessageBox.Show(“添加成功“);
                    }
                    else {
                        MessageBox.Show(“添加失败“);
                    }
                }
                catch (Exception)
                {

                    throw;
                }
                finally {

                    con.Close();
                }
            }
            else {
                MessageBox.Show(“请填写完整“);
            }
        }

        private void btnquery_Click(object sender EventArgs e)
        {
            if (txtid.Text != ““)
            {
                string id = txtid.Text;
                string str = “server=.;database=SchoolManager;uid=sa;pwd=root“;
                SqlCo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-21 17:01  CDemo\
     目录           0  2018-07-21 09:49  CDemo\.vs\
     目录           0  2018-07-21 09:49  CDemo\.vs\CDemo\
     目录           0  2018-07-21 09:49  CDemo\.vs\CDemo\v14\
     文件       48128  2018-07-21 17:02  CDemo\.vs\CDemo\v14\.suo
     文件         985  2018-07-21 11:18  CDemo\CDemo.sln
     目录           0  2018-07-21 17:01  CDemo\CDemo1\
     文件         189  2018-07-21 09:48  CDemo\CDemo1\App.config
     目录           0  2018-07-21 09:51  CDemo\CDemo1\bin\
     目录           0  2018-07-21 09:52  CDemo\CDemo1\bin\Debug\
     文件      176640  2018-07-21 16:56  CDemo\CDemo1\bin\Debug\CDemo1.exe
     文件         189  2018-07-21 09:48  CDemo\CDemo1\bin\Debug\CDemo1.exe.config
     文件       42496  2018-07-21 16:56  CDemo\CDemo1\bin\Debug\CDemo1.pdb
     文件       22696  2018-07-21 17:01  CDemo\CDemo1\bin\Debug\CDemo1.vshost.exe
     文件         189  2018-07-21 09:48  CDemo\CDemo1\bin\Debug\CDemo1.vshost.exe.config
     目录           0  2018-07-21 09:51  CDemo\CDemo1\bin\Release\
     文件        4543  2018-07-21 12:13  CDemo\CDemo1\CDemo1.csproj
     文件        7135  2018-07-21 17:01  CDemo\CDemo1\frmadd.cs
     文件       15213  2018-07-21 16:50  CDemo\CDemo1\frmadd.Designer.cs
     文件        5817  2018-07-21 16:50  CDemo\CDemo1\frmadd.resx
     文件        2135  2018-07-21 12:02  CDemo\CDemo1\frmLogin.cs
     文件        6286  2018-07-21 11:51  CDemo\CDemo1\frmLogin.Designer.cs
     文件      230638  2018-07-21 11:51  CDemo\CDemo1\frmLogin.resx
     文件        7810  2018-07-21 16:56  CDemo\CDemo1\frmset.cs
     文件       16056  2018-07-21 16:56  CDemo\CDemo1\frmset.Designer.cs
     文件        6011  2018-07-21 16:56  CDemo\CDemo1\frmset.resx
     目录           0  2018-07-21 09:48  CDemo\CDemo1\obj\
     目录           0  2018-07-21 16:56  CDemo\CDemo1\obj\Debug\
     文件         640  2018-07-21 17:01  CDemo\CDemo1\obj\Debug\CDemo1.csproj.FileListAbsolute.txt
     文件        1097  2018-07-21 16:56  CDemo\CDemo1\obj\Debug\CDemo1.csproj.GenerateResource.Cache
     文件        2384  2018-07-21 09:52  CDemo\CDemo1\obj\Debug\CDemo1.csprojResolveAssemblyReference.cache
............此处省略19个文件信息

评论

共有 条评论