Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, i am newbie in c#. i have sqlsitemapprovider and stored procedure. i having this problem at this row in sqlsitemapprovider:

DataRow rowRoot = dtSiteMap.Select("[parentId] IS NULL")[0]; //problemhere //

this problem occur everytime i filter my idUserRole in my stored procedure but my dynamic menu bar will work if i did not filter my idUserRole. i already check my datatable, it is empty when i did filter it by idUserRole and it filled if i did not filter it by idUserRole. i stuck in this problem for two week, i have go through every forum but still did not find any solution.

my code sqlsitemapprovider:

C#
DataSet ds = new DataSet();
adapter.Fill(ds, "modulemain");
DataTable dt = new DataTable();
DataTable dtSiteMap = ds.Tables["modulemain"];

DataRow rowRoot = dtSiteMap.Select("[parentId] IS NULL")[0]; //problemhere //

rootNode = new SiteMapNode(this,
rowRoot["url"].ToString(), rowRoot["url"].ToString(),
rowRoot["description"].ToString(), rowRoot["description"].ToString());
string rootID = rowRoot["moduleId"].ToString();


my stored procedure:

SQL
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_SiteMap`()

BEGIN
SELECT A.moduleId, A.Code,A.description,A.url,A.parent AS parentId,A.sequence
, C.`description` AS RoleDesc,D.idUser
FROM modulemain A
LEFT JOIN `moduleitem` B ON A.`moduleId` = B.`ModuleId` AND B.`active` = 1
LEFT JOIN `usermodule` C ON B.`UserModuleId` = C.`idUserModule`
LEFT JOIN `user` D ON C.`idUserModule` = D.`idUserRole`
WHERE A.active = 1 AND D.idUserRole = @idUserRole
ORDER BY A.parent, A.Code, A.sequence;

END$$



any suggestion? many thanks! May god bless you guys!
Posted
Updated 8-Apr-14 18:13pm
v2

1 solution

Change from:

DataRow rowRoot = dtSiteMap.Select("[parentId] IS NULL")[0]; //problemhere //

To:

var res = from row in dt.AsEnumerable()
where row["parentID"] == null
select row;

if(res.Any()){
DataRow rowRoot = res.First();
} else {
//TODO: Implement appropriate handling of cas where there is a parentId
}

Point being that don't presume there is a number 0 (first) until you know there is, this is your problem
 
Share this answer
 
v2
Comments
mariana94 9-Apr-14 20:42pm    
hi Thomas, many thank for answering my question but sadly it still cannot solve. =(. btw, thanks for the advise. =)
Thomas Nielsen - getCore 10-Apr-14 4:19am    
Hi Mariana
You're very welcome. Perhaps you're experiencing what nother one has experience here:
http://stackoverflow.com/questions/9324088/how-to-use-datatable-select-to-select-null-empty-values. The values are not actually null but changed to be zero length strings?

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