SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-FQHBJBO;Initial
Catalog=star_platinum;Integrated Security=True;");
For Insertion of data into table:
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Inventory (Productid, ProductName, ProductPrice,
Productcategory,ProductQuantity,ProductDescription) VALUES (@Value1, @Value2,
@Value3, @Value4, @Value5, @Value6)";
cmd.Parameters.AddWithValue("@Value1", textBox4.Text);
cmd.Parameters.AddWithValue("@Value2", textBox13.Text);
cmd.Parameters.AddWithValue("@Value3", textBox14.Text);
cmd.Parameters.AddWithValue("@Value4", textBox4.Text);
cmd.Parameters.AddWithValue("@Value5", textBox10.Text);
cmd.Parameters.AddWithValue("@Value6", textBox12.Text);
cmd.ExecuteNonQuery();
con.Close();
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
disp_data();
MessageBox.Show("Record Inserted Successfully!");
For Selection of data from table:
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from Inventory";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close()