habib ullah

habib ullah

  • NA
  • 229
  • 14.4k

how to save the datagraidview selected rows in database

Apr 14 2018 10:03 AM
how to save the datagraidview selecter rows save in database if some rows checked in the grid
 
they insert the only one record in database pleas help me i am beginner
 
private void button1_Click(object sender, EventArgs e)
{
bool ReturnStatus = true;
String ReturnMessage = "";
//int ClassId =1;
try
{
//call function to save the data in database...
for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
if ((bool)dataGridView1.Rows[i].Cells["chk"].Value == true)
{
List<SqlParameter> PRM = new List<SqlParameter>();
PRM.Add(new SqlParameter() { ParameterName = "@ClassName", Value = tbx_classname.Text });
PRM.Add(new SqlParameter() { ParameterName = "@Subject_Id", Value =dataGridView1.Rows[i].Cells["id"]});
PRM.Add(new SqlParameter() { ParameterName = "@TotalMarks", Value = dataGridView1.Rows[i].Cells["TotalMarks"]});
PRM.Add(new SqlParameter() { ParameterName = "@PassingMarks", Value = dataGridView1.Rows[i].Cells["PassingMarks"]});
rp.dbManage("[School].[CreateClass]", PRM, out ReturnStatus,out ReturnMessage);
MessageBox.Show(ReturnMessage.ToString());
}
}

Answers (1)