abujafar
abujafar

Reputation: 131

can't cast sqlViewResults to DataRowView

I am working on an asp.net page and trying to improve its load time. It takes about 8 seconds to load 20 records in a listview.

The page was loading properly in spite of being slow using eval as follows:

<asp:LinkButton CommandArgument='<%#Eval("EmployeeID")%>' >Edit</asp:LinkButton>

However, because the previous approach was slow, I changed it to the following based on info I read here:

<asp:LinkButton CommandArgument='<%# ((DataRowView)Container.DataItem)["ApplicationID"]%>'>Edit</asp:LinkButton>

However the new code produces the following error: Unable to cast object of type DataObjects.Data.EmployeeInfo to type 'System.Data.DataRowView

Now, I am not that familiar with the second method but the load time of the first method is unacceptable. things to Note:

the sample code I saw used DataRowView and DataItem. Am I supposed to change DataRowView or DataItem to something else? What do I need to do to correct this error?

Upvotes: 0

Views: 49

Answers (1)

Mehdi Ibrahim
Mehdi Ibrahim

Reputation: 2624

Change <asp:LinkButton CommandArgument='<%# ((DataRowView)Container.DataItem)["ApplicationID"]%>'>Edit</asp:LinkButton>

to

<asp:LinkButton CommandArgument='<%# ((DataObjects.Data.EmployeeInfo)Container.DataItem).ApplicationID %>'>Edit</asp:LinkButton>

This is unlikely to make any significant improvement to your load time though. 8 seconds to load 20 records is almost certainly unrelated to Eval or casting. It would likely indicate a performance issue in your stored procedure/database code. You should run SQL Server Profiler to get an accurate sense of how long your database query is taking. If it is confirmed that the issue is with your stored procedure/view, then you can use SSMS Query Analyzer to identify bottlenecks and what you could do to improve performance. If you want to post your Query Analyzer results, we can further help you from there.

Upvotes: 1

Related Questions