基本信息
源码名称:C# 通讯录源码,实现了增删改功能(含数据库下载)
源码大小:1.56M
文件格式:.zip
开发语言:C#
更新时间:2015-12-21
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
//download by http://www.codefans.net
namespace PersonInfoInsert
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            int age;
            try
            {
                age = int.Parse(this.txtage.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("年纪必须是数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string sql = string.Format("insert into userinfo values('{0}',{1},'{2}','{3}','{4}')",this.txtname.Text,age,this.cboQuo.Text,this.txtphone.Text,this.txtaddress.Text);
            try
            {
                DBhelper.con.Open();
                SqlCommand cmd = new SqlCommand(sql, DBhelper.con);
                int k = cmd.ExecuteNonQuery();
                if (k == 1)
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                }

            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                DBhelper.con.Close();
            }
        }
        // 下载于www.51aspx.com
        private void btnupdate_Click(object sender, EventArgs e)
        {
            int age;
            try
            {
                age = int.Parse(this.txtage.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("年纪必须是数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string sql = string.Format("Update  UserInfo set age={0},qualification='{1}',phone='{2}',address='{3}' where UserName='{4}'",age,this.cboQuo.Text,this.txtphone.Text,this.txtaddress.Text,this.txtname.Text);
            try
            {
                DBhelper.con.Open();
                SqlCommand cmd = new SqlCommand(sql, DBhelper.con);
                int k = cmd.ExecuteNonQuery();
                if (k == 1)
                {
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show("修改失败");
                }

            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                DBhelper.con.Close();
            }
        }

        private void btndel_Click(object sender, EventArgs e)
        {
            string sql = string.Format("delete userinfo where UserName='{0}'",this.txtname.Text);
            try
            {
                DBhelper.con.Open();
                SqlCommand cmd = new SqlCommand(sql, DBhelper.con);
                int k = cmd.ExecuteNonQuery();
                if (k == 1)
                {
                    MessageBox.Show("成功");
                }
                else
                {
                    MessageBox.Show("删除失败");
                }

            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                DBhelper.con.Close();
            }
        }
    }
}