Reputation: 91
Hi Hope someone can help.
I am trying to render a list of all my product url's I am using ASP.NET WEBpages (not WebForms or MVC).
But if the Database query is over a certain amount of records it gives me the following error.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
If I put into the SQL query Top 500 it works fine.
my db query
var db = Database.Open("MyConnectionString");
var Products = "SELECT Top 500* FROM shop_products WHERE site_id = '99' AND product_active = 'Y' ORDER BY product_name ASC";
I used to be able to do this in Classic ASP.
Might there be a limit on SQL query sizes in asp.net, If so how do i get around this.
Help
Upvotes: 1
Views: 233
Reputation: 91
To solve this I split this down into smaller SQL query's, split out by the category's the products where in.
Upvotes: 0
Reputation: 2133
The key phrase in the error message is "cannot perform runtime binding on a null reference".
I suspect that the top 500 rows in the "shop_products" table did not have a column value with a NULL value. That is why that select worked and the select without the "top 500" qualifier did not.
Your code needs to detect DBnull values and assign a default value for these cases or do some sort of error processing to avoid this runtime error.
Upvotes: 1