diptibhatore 0 Newbie Poster
protected void Button1_Click(object sender, EventArgs e)
    {
      SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["shortycaponeConnectionString"].ConnectionString);
     
       for (int i = 0; i < GridView1.Rows.Count; i++)
       {
           GridViewRow row = GridView1.Rows[i];
           CheckBox chkbox = (CheckBox)row.FindControl("cbRows");
           TextBox Quantity = (TextBox)row.FindControl("tbx_TextBox");

           if (chkbox.Checked == true)
           {
               try
               {
                   con.Open();
                   SqlCommand cmd = new SqlCommand("INSERT INTO InwardEntries(ProductCode,Size,Quantity,DateTimeNow) VALUES (@ProductCode,'" + row.Cells[1].Text + "','" + Quantity.Text + "','" + TextBox1.Text + "')", con);
                   cmd.Parameters.AddWithValue("@ProductCode", DropDownList4.Text);
                   cmd.Parameters.AddWithValue("@DateTime", TextBox1.Text);
                   cmd.ExecuteNonQuery();

                   SqlCommand cmd2 = new SqlCommand("update Quantity1 set Quantity = Quantity +'" + Quantity.Text + "' where ProductCode='" + DropDownList4.SelectedItem.Text + "'", con);
                   cmd2.Parameters.AddWithValue("@ProductCode", DropDownList4.Text);
                   //cmd2.Parameters.Add("@qty", SqlDbType.Float);
                   cmd2.ExecuteNonQuery();
                   con.Close();
               }
               catch
               {
                   Response.Write("");

               }
               finally
               {
                   con.Close();
               }




           }
       }