Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 MySql.Data.MySqlClient;
- namespace form1
- {
- public partial class addProduct : Form
- {
- public addProduct()
- {
- InitializeComponent();
- fillcombocat();
- }
- MySqlConnection con = new MySqlConnection("server = 'localhost'; database = 'arabia'; username = 'root'; password = '123'");
- void fillcombocat()
- {
- string catquery = "select * from category";
- MySqlCommand cmd = new MySqlCommand(catquery, con);
- con.Open();
- DataSet ds = new DataSet();
- MySqlDataAdapter ada = new MySqlDataAdapter(cmd);
- ada.Fill(ds);
- comboBox1.DataSource = ds.Tables[0];
- comboBox1.DisplayMember = "name";
- comboBox1.ValueMember = "idno";
- con.Close();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- MySqlCommand cmd = new MySqlCommand();
- cmd.Connection = con;
- cmd.Connection = con;
- cmd.CommandText = "insert into product(Name,Category,Description,Price)values(@Name,@Category,@Description,@Price)";
- cmd.Parameters.AddWithValue("Name", textBox1.Text);
- cmd.Parameters.AddWithValue("Catergory", comboBox1.SelectedValue);
- cmd.Parameters.AddWithValue("Description", textBox2.Text);
- cmd.Parameters.AddWithValue("Price", textBox3.Text);
- con.Open();
- cmd.ExecuteNonQuery();
- MessageBox.Show("Record added");
- con.Close();
- }
- private void Product_Load(object sender, EventArgs e)
- {
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- this.Hide();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement