How to write a code where rows of some column are not fixed?
I am stuck up in a pretty bad situation. I am having db columns such as mentioned below;
* Season Name People died (in US+UK+Asia)*
Winter 98
Fall 14
Rainy 148
Other 开发者_JAVA百科 07
Now if there are no people who died in any of the season (say Fall season) then the row showing fall season is omitted. Hence the SP now returns the data something like;
* Season Name People died (in US+UK+Asia)*
Winter 98
Rainy 148
Other 07
Problem: I need to assign the values (second column) to the variables. I am fetching the SP result in dataset. But i don't know how to find the values that are not omitted (Winter, Rainy, Other as seen above) and assign them to their respective variables. In that case the variable for fall season would be assigned 0.
Let me know if there is any query.
please help!.
Regards
You have a few options here, but if you don't have database access (and from the comments above, it looks like you don't):
- Find a query that lists all of the possible seasons. Use that query to instantiate a class that combines seasons and deaths, and then add each instance to an Enumerable of some sort. Use that Enumerable to populate your webpage.
- Talk to a DBA or someone on your DB team. I'm taking a stab in the dark here, but it sounds like your database has seasons listed in one table and deaths-per-season listed in another table. If I'm right, then whoever wrote this query performed an
INNER JOIN
from seasons to deaths-per-season instead ofLEFT JOIN
ing seasons to deaths-per-season, which would return all seasons regardless of whether or not they have any deaths.
You could also add each season that you're aware of to a const string[]
, but that's a kludge to get around the fact that you don't have easy database access. If you meet with a lot of resistance on this topic, try explaining that you need to display all of these seasons to the user and that you need the stored procedure updated.
Good luck!
精彩评论