Insert.cs
上传用户:nbcygd
上传日期:2008-07-25
资源大小:2566k
文件大小:2k
源码类别:

SQL Server

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.Sql;
  9. using System.Data.SqlClient;
  10. using System.Data.SqlTypes;
  11. namespace Super_market
  12. {
  13.     public partial class Insert : Form
  14.     {
  15.         private SqlDataAdapter da;
  16.         private SqlConnection con;
  17.         private SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
  18.         private DataSet ds;                
  19.         public delegate void dele();
  20.         public event dele evt;
  21.         public Insert()
  22.         {
  23.             InitializeComponent();
  24.             b.DataSource = ".";
  25.             b.InitialCatalog = "wkdl";
  26.             b.IntegratedSecurity = true;
  27.             con = new SqlConnection(b.ConnectionString);
  28.             da = new SqlDataAdapter("select id as 商品编号,warename as 商品名称,price as 单价,entries as 已售出数量,keep as 保质期 from ", con);
  29.             ds = new DataSet();
  30.         }
  31.         private void button2_Click(object sender, EventArgs e)
  32.         {
  33.             this.Dispose();
  34.         }
  35.         private void button1_Click(object sender, EventArgs e)
  36.         {
  37.             
  38.                 if (textBox1.Text.Length != 0 && textBox2.Text.Length != 0 && textBox3.Text.Length != 0 && textBox4.Text.Length != 0 )
  39.                 {
  40.                     try
  41.                     {
  42.                         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())+")";
  43.                         da.InsertCommand = con.CreateCommand();
  44.                         da.InsertCommand.CommandText = str;
  45.                         con.Open();
  46.                         da.InsertCommand.ExecuteNonQuery();
  47.                         con.Close();
  48.                         MessageBox.Show("cccc");
  49.                         this.Dispose(true);
  50.                         evt();
  51.                     }
  52.                     catch (Exception ex)
  53.                     {
  54.                         MessageBox.Show(ex.Message);
  55.                     }
  56.                     finally
  57.                     {
  58.                         con.Close();
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     MessageBox.Show("sssss");
  64.                 }
  65.             }      
  66.     }
  67. }