Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
4.11/5 (2 votes)
See more:
I am very frustrated that in my application I am using data adapter to fill datatable but it is taking much more time to fill the datatable. In my application scenario I want full data in datatable and in SQL Server management studio it takes only seconds to show the data.
I have tried datareader and dataadapter but it taking more time. Current record size is 10000+ and it may increase so now its taking 2-4 minuts and if database records increase then it will take more time. My project developed in C#2.0 only.

I am using below code for fill datatable. I also tried with datatable load method with datareader.
C#
SqlConnection connection=new SqlConnection("connectionString");
connection.Open();
SqlCommand cmd = new SqlCommand("StoredProcedureName", connection);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@param1", 16));
cmd.Parameters.Add(new SqlParameter("@ID", 341));
cmd.Parameters.Add(new SqlParameter("@LOCATION", "Bank Street"));
cmd.Parameters.Add(new SqlParameter("@NAME", "Prince"));
DataTable dt = new DataTable();
new SqlDataAdapter(cmd).Fill(dt);
connection.close();


Please give me better solution for it.

Thanks in Advance :)
Posted
Updated 4-Aug-14 19:30pm
v5
Comments
gggustafson 1-Aug-14 11:11am    
Are you using a view to retrive your data?
Member 10420430 4-Aug-14 1:11am    
No. I am not using view. I am using stored procedure and select statement . Stored procedure created by DBA.
gggustafson 4-Aug-14 10:24am    
Click on Improve question and add the DB code (from connection thru DataTable fill).
Herman<T>.Instance 8-Aug-14 7:00am    
is the datatable really he problem or he component used to show the data? Add timers around
new SqlDataAdapter(cmd).Fill(dt);
and see in a timespan how long hat loading really takes
Member 10420430 8-Aug-14 7:52am    
I already used timer and its taking too much time. It takes more that 2-4 minutes for fill data table.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900