protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString());
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox chkbox = (CheckBox)row.FindControl("chkboxSelect");
TextBox UnitPrice = (TextBox)row.FindControl("txtUnitPrice");
if (chkbox.Checked == true)
{
try
{
conn.Open();
int Supp = Convert.ToInt16(Request.QueryString["SupplierId"]);
SqlCommand cmd = new SqlCommand ("INSERT INTO SuppMat (SupplierId, MaterialID, UnitPrice) VALUES (@SupplierId,'" + row.Cells[1].Text + "','" + UnitPrice.Text + "')", conn);
cmd.Parameters.AddWithValue("@SupplierId", Supp);
cmd.ExecuteNonQuery();
conn.Close();
}
catch
{
Response.Write("");
}
finally
{
conn.Close();
}
}
}
}
here's my code..my only problem now is that it does not save to the database.. hope you can help me..