Reputation: 875
I would like to ask for faster way in filling datagrid from dataset. I'm working with huge volume of data (approximately of 8000 of rows). I'm using C#.net . I have two version of codes (below) both of them took almost one minute to finish the loading of data.
// First Code
DataSet objDataSet = new DataSet();
objDataSet = objMemberShip.mtdMemberViewBy(strGlobalUserID, 0, "", ref intErrNo);
datagrid1.DataSource = objDataSet.Tables[0];
// Second Code
objDataSet = objMemberShip.mtdMemberViewBy(strGlobalUserID, 0, "", ref intErrNo);
datagrid1.Rows.Clear();
for (int intCount = 0; intCount <= objDataSet.Tables[0].Rows.Count - 1; intCount++)
{
string[] strRow = new string[] { objDataSet.Tables[0].Rows[intCount] ["trTranId"].ToString(), objDataSet.Tables[0].Rows[intCount]["strCEMCode"].ToString(),
objDataSet.Tables[0].Rows[intCount]["strName"].ToString(), objDataSet.Tables[0].Rows[intCount]["strAddress"].ToString(),
objDataSet.Tables[0].Rows[intCount]["strTestCenterId"].ToString(), objDataSet.Tables[0].Rows[intCount]["TCr_Name"].ToString(),
objDataSet.Tables[0].Rows[intCount]["strMemberId"].ToString(), objDataSet.Tables[0].Rows[intCount]["TCr_GL_Code"].ToString()};
datagrid1.Rows.Add(strRow);
}
Upvotes: 0
Views: 401
Reputation: 44605
The first approach should be fine I believe MS has done things properly in databinding and you wouldnt be faster with your own loops. Is the delay in loading the data or binding to grid? if you have too many rows you should page as makes no sense to show thousands of rows at once.
Upvotes: 1
Reputation:
And identify the line where most time is taken. It can probably be this line -
objDataSet = objMemberShip.mtdMemberViewBy(strGlobalUserID, 0, "", ref intErrNo);
Might be a service call which might be calling a procedure at database. Delay can also be at the procedure level.
Upvotes: 0