We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
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()