首页 > 数据库技术 > 详细

2017-04-25数据库编程截图

时间:2017-04-25 20:45:15      阅读:222      评论:0      收藏:0      [点我收藏+]

技术分享

 

技术分享  技术分享   技术分享   技术分享   

 

技术分享     技术分享   技术分享 技术分享    技术分享 

 

技术分享

 

 

 

 技术分享

 技术分享

 技术分享

技术分享技术分享        

 

 

技术分享    技术分享   技术分享   技术分享   技术分享  技术分享  技术分享   技术分享   技术分享  技术分享 技术分享  技术分享  技术分享  技术分享    技术分享   技术分享    技术分享   

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;//连接数据
using System.Configuration;

namespace ERPforms
{
    public partial class Form1 : Form
    {
        //定义错误信息
        string[] strMessage = new string[]{
            "编号不能为空!","物料不能为空!","价格或输入格式不对!"
        };
        public Form1()
        {
            InitializeComponent();
        }
        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }
        private void label1_Click(object sender, EventArgs e)
        {

        }
        private void btnSave_Click(object sender, EventArgs e)
        {

        }
        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        //保存数据(新增物料)
        private void btmsave_Click(object sender, EventArgs e)
        {
            if (Validation() != -1)
                MessageBox.Show(strMessage[Validation()]);
            else
            {
                AddItems();
            }
        }
        //添加物料信息
        private void AddItems()
        {
            //连接数据库
            string connString = ConfigurationManager.ConnectionStrings["connString"].ToString();
            SqlConnection conn = new SqlConnection(connString);//实例化连接对象
            string sql = "insert into Items values(" + txtNo.Text + "," + "" + txtName.Text + "," + txtAge.Text + "," + txtPlace.Text + ")";
            //数据库操作
            conn.Open();//打开连接
            try
            {
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }

        }
        //数据验证
        private int Validation()
        {
            int price = 0;
            int status = -1;
            if (txtNo.Text == "")//验证编号
                status = 0;
            else if (txtName.Text == "")
                status = 1;
            else if (txtAge.Text == "" &&
                int.TryParse(txtAge.Text, out price))
                status = 2;
            return status;

        }
    }
}

全选在粘贴代码进去

技术分享  技术分享    技术分享

 

   技术分享   技术分享

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="connString" connectionString="Data Source=.;
  Initial Catalog=ErpDb;Integrated Security=True"/>
  </connectionStrings>
</configuration>

 

技术分享     技术分享   技术分享   技术分享  技术分享   技术分享    技术分享  技术分享

 

 

 

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

2017-04-25数据库编程截图

原文:http://www.cnblogs.com/liangjinjie/p/6763156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!