hi
refer below link
http://www.aspforums.net/Threads/999041/bind-2-level-menu-from-database/?s=2#Replies
I use code for 2levelmenu now I want bind it from database so I change code like below
private DataTable GetMenu()
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("BindMenu", conn))
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter();
conn.Open();
sda.SelectCommand = _cmd;
sda.Fill(dt);
return dt;
}
}
protected DataTable GetSubMenu(string manuId)
{
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("Bind2levelMenu", conn))
{
_cmd.Parameters.Add("@MenuId", string.Format("menuId = {0}", manuId));
DataTable dt = new DataTable();
try
{
conn.Open();
SqlDataReader reader = _cmd.ExecuteReader();
if (reader.HasRows)
{
dt.Load(reader);
}
reader.Close();
}
catch (Exception)
{
return new DataTable();
}
}
}
protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rptSubMenu = e.Item.FindControl("rptSubMenu") as Repeater;
string manuId = (e.Item.DataItem as DataRowView)["Id"].ToString();
rptSubMenu.DataSource = this.GetSubMenu(manuId);
rptSubMenu.DataBind();
}
and SP
create procedure [dbo].[Bind2levelMenu]
@MenuId int
as
begin
select *
from Menu
where Id=@MenuId
end
but this error happen:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0161: 'menu.GetSubMenu(string)': not all code paths return a value
Source Error:
|
Line 115:
Line 116:
Line 117: protected DataTable GetSubMenu(string manuId)
Line 118: {
Line 119:
|
I think I worte below metod wrong
protected DataTable GetSubMenu(string manuId)
can you help me please
Best Regards
Neda