Advertisement
mamararabia

Products

Jul 15th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10.  
  11. namespace form1
  12. {
  13.     public partial class addProduct : Form
  14.     {
  15.        
  16.         public addProduct()
  17.         {
  18.             InitializeComponent();
  19.             fillcombocat();
  20.  
  21.         }
  22.         MySqlConnection con = new MySqlConnection("server = 'localhost'; database = 'arabia'; username = 'root'; password = '123'");
  23.  
  24.         void fillcombocat()
  25.  
  26.             {
  27.                 string catquery = "select * from category";
  28.                 MySqlCommand cmd = new MySqlCommand(catquery, con);
  29.                 con.Open();
  30.                 DataSet ds = new DataSet();
  31.                 MySqlDataAdapter ada = new MySqlDataAdapter(cmd);
  32.                 ada.Fill(ds);
  33.                 comboBox1.DataSource = ds.Tables[0];
  34.                 comboBox1.DisplayMember = "name";
  35.                 comboBox1.ValueMember = "idno";
  36.                 con.Close();
  37.            
  38.  
  39.             }
  40.        
  41.  
  42.         private void textBox1_TextChanged(object sender, EventArgs e)
  43.         {
  44.  
  45.         }
  46.  
  47.         private void button1_Click(object sender, EventArgs e)
  48.         {
  49.  
  50.             MySqlCommand cmd = new MySqlCommand();
  51.             cmd.Connection = con;
  52.             cmd.Connection = con;
  53.             cmd.CommandText = "insert into product(Name,Category,Description,Price)values(@Name,@Category,@Description,@Price)";
  54.             cmd.Parameters.AddWithValue("Name", textBox1.Text);
  55.             cmd.Parameters.AddWithValue("Catergory", comboBox1.SelectedValue);
  56.             cmd.Parameters.AddWithValue("Description", textBox2.Text);
  57.             cmd.Parameters.AddWithValue("Price", textBox3.Text);
  58.  
  59.  
  60.             con.Open();
  61.             cmd.ExecuteNonQuery();
  62.             MessageBox.Show("Record added");
  63.             con.Close();
  64.         }
  65.            
  66.        
  67.  
  68.         private void Product_Load(object sender, EventArgs e)
  69.         {
  70.  
  71.         }
  72.  
  73.      
  74.  
  75.         private void textBox3_TextChanged(object sender, EventArgs e)
  76.         {
  77.  
  78.         }
  79.  
  80.         private void button2_Click_1(object sender, EventArgs e)
  81.         {
  82.             this.Hide();
  83.         }
  84.  
  85.      
  86.  
  87.      
  88.        
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement