protected void QuantityAddButton_Click(object sender, EventArgs e) { String cs = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("insert into ProductQuantityTable values('" + ProductDropDownId.SelectedItem.Value + "','" + ProductQuantityTextBox.Text + "')", con); con.Open(); cmd.ExecuteNonQuery(); ProductQuantityTextBox.Text = string.Empty; ProductDropDownId.ClearSelection(); ProductDropDownId.Items.FindByValue("0").Selected = true; } }
private void BindAllProductId() { String cs = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("select * from ProductTable ", con); con.Open(); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); //Response.Write(dt1.Rows.Count); if (dt.Rows.Count != 0) { ProductDropDownId.DataSource = dt; ProductDropDownId.DataTextField = "ProductName"; ProductDropDownId.DataValueField = "ProductId"; ProductDropDownId.DataBind(); ProductDropDownId.Items.Insert(0, new ListItem("-Select-", "0")); } } }