my application is in windows form(c#) which needs multiple insertion(say 500 times in one go) in sql server 2008 database.I am destroying the command objects, connection objects. It works fine for some occurrences but than it hangs. what more can be done to make it more effective.
if a pause is taken between than its ok but if continuously done than application hangs.
My app picks Enrollment_No and Card_Id from one table and along with those inserts in second table.
Any suggestion it make it more efficient will be heartly accepted...
clscommon lCommon1 = new clscommon();
lCommon1.SetAdapterObject("select Enrollment_No,Card_Id from Student_Details");
lCommon1.lAdapter.Fill(DsGrid);
lCommon1.DestroyAdapterObject();
lCommon1 = null;
foreach (DataGridViewRow Row in dataGridView1.Rows)
{
if (Row.Cells[0].Value.ToString().Trim() != "")
{
bool Chkinrt = false;
string StuCardId = "";
for (int dsC = 0; dsC <= DsGrid.Tables[0].Rows.Count; dsC++)
{
if (DsGrid.Tables[0].Rows[dsC]["Enrollment_No"].ToString() == Row.Cells[0].Value.ToString().Trim())
{
StuCardId = DsGrid.Tables[0].Rows[dsC]["Card_Id"].ToString();
Chkinrt = true;
break;
}
}
if (Chkinrt == true)
{
clscommon lCommon3 = new clscommon();
lCommon3.SetCommandObject("insert into EnrollReg(RegId,Enrollment_No,Card_Id) values(@RegId,@Enrollment_No,@Card_Id)");
lCommon3.AddParameterInCommandObject("RegId", RegID);
lCommon3.AddParameterInCommandObject("Enrollment_No", Row.Cells[0].Value.ToString().Trim());
lCommon3.AddParameterInCommandObject("Card_Id", StuCardId);
lCommon3.objCommand.ExecuteNonQuery();
lCommon3.DestroyCommandObject();
lCommon3 = null;
}
}
}
MessageBox.Show("Student's Class Record Added Successfully");