Friday, 27 July 2012

INSERT MULTIPLE ROWS  IN DATABASE FROM A GRID VIEW 

protected void btnsave_Click(object sender, EventArgs e)
        {
     
            for (int i = 0; i < Grid_fee.Rows.Count; i++)
            {
                TextBox amount = (TextBox)Grid_fee.Rows[i].Cells[1].FindControl("txt_amount");
                Label semeid = (Label)Grid_fee.Rows[i].Cells[1].FindControl("lbl_semeid");

                cm.amount = amount.Text;
                cm.memberid = Convert.ToInt64(Session["MemberID"].ToString());
             
                cm.semesterid=Convert.ToInt64(semeid.Text);
                cm.enteredby = Convert.ToInt64(Session["UserID"]);
                cm.feessave();
              
            }
          
        }

class file
namespace AccessLayer
{
    public class CommonMaster
    {
        public System.Int64 memberid
        {
            get;
            set;
        }
        public System.Int64 semesterid
        {
            get;
            set;
        }
        public System.String amount
        {
            get;
            set;
        }
      
        public System.Int64 enteredby
        {
            get;
            set;
        }
      public DataSet feessave()
        {
            SqlCommand cmdfees = new SqlCommand();
             cmdfees.CommandType = CommandType.StoredProcedure;
            cmdfees.CommandText = "studentfee_insert";
            cmdfees.Parameters.AddWithValue("@memberid", memberid);
            cmdfees.Parameters.AddWithValue("@semesterid", semesterid);
            cmdfees.Parameters.AddWithValue("@amount", amount);
            cmdfees.Parameters.AddWithValue("@enteredby", enteredby);
            con.open();
            cmd.executeNonQuery();
             
        }

No comments:

Post a Comment