con.Open();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string sql = "Select * from MenuControl";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(ds);
dt = ds.Tables[0];
foreach (DataRow dr in dt.Select("ParentId=" + 0))
{
if (dr["MenuName"] != null && dr["MenuId"] != null && dr["LocationUrl"] != null)
{
menuBar.Items.Add(new MenuItem(dr["MenuName"].ToString(), dr["MenuId"].ToString(), "", dr["LocationUrl"].ToString()));
}
}
foreach (DataRow dr in dt.Select("ParentId>" + 0))
{
if (dr["MenuName"] != null && dr["MenuId"] != null && dr["LocationUrl"] != null)
{
MenuItem mnu = new MenuItem(dr["MenuName"].ToString(), dr["MenuId"].ToString(), "", dr["LocationUrl"].ToString());
if (dr["ParentId"] != null)
{
menuBar.FindItem(dr["ParentId"].ToString()).ChildItems.Add(mnu);
}
}
}
con.Close();
error given
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
|
database table
SELECT TOP 1000 [MenuId]
,[MenuName]
,[LocationUrl]
,[ParentId]
FROM [SMSSystem].[dbo].[MenuControl]

Riddhi ValechaRank #794 · 2.9K reputationPosted Oct 13, 2013, 3:13 AM EDT
please share your code.......
VulpesRank #55 · 29.2K reputationPosted Oct 13, 2013, 4:27 AM EDT