Insert.cs
上传用户:nbcygd
上传日期:2008-07-25
资源大小:2566k
文件大小:2k
- 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.Sql;
- using System.Data.SqlClient;
- using System.Data.SqlTypes;
- namespace Super_market
- {
- public partial class Insert : Form
- {
- private SqlDataAdapter da;
- private SqlConnection con;
- private SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
- private DataSet ds;
- public delegate void dele();
- public event dele evt;
- public Insert()
- {
- InitializeComponent();
- b.DataSource = ".";
- b.InitialCatalog = "wkdl";
- b.IntegratedSecurity = true;
- con = new SqlConnection(b.ConnectionString);
- da = new SqlDataAdapter("select id as 商品编号,warename as 商品名称,price as 单价,entries as 已售出数量,keep as 保质期 from ", con);
- ds = new DataSet();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Dispose();
- }
- private void button1_Click(object sender, EventArgs e)
- {
-
- if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0 && textBox3.Text.Length != 0 && textBox4.Text.Length != 0 )
- {
- try
- {
- string str = "insert into ware (id ,warename ,price,keep) values("+int.Parse(textBox1.Text.Trim().ToString())+ ",'"+textBox2.Text.Trim().ToString()+"',"+double.Parse(textBox3.Text.Trim().ToString())+","+int.Parse(textBox4.Text.Trim().ToString())+")";
- da.InsertCommand = con.CreateCommand();
- da.InsertCommand.CommandText = str;
- con.Open();
- da.InsertCommand.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("cccc");
- this.Dispose(true);
- evt();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- con.Close();
- }
- }
- else
- {
- MessageBox.Show("sssss");
- }
- }
- }
- }