pls try this
foreach (GridViewRow row in gvClassRooms.Rows)
{
if (!string.IsNullOrEmpty(row.Cells[1].Text))
{
Sql = "insert into TB_Room_Allocation_SMS (RoomNo,Minor_Code) " +
"values( '" + row.Cells[0].Text + "','" + row.Cells[1].Text + "')";
scon.ExecSql(Sql);
}
if (!string.IsNullOrEmpty(row.Cells[3].Text))
{
Sql = "insert into TB_Room_Allocation_SMS (RoomNo,Minor_Code) " +
"values( '" + row.Cells[2].Text + "','" + row.Cells[3].Text + "')";
scon.ExecSql(Sql);
}
Label4.Text = "Records Inserted Successfully";
scon.Con.Close();
}
Hope this will help...