如果我在asp.net中使用Sql Server数据库进行动态菜单绑定,则会在页面上显示菜单和子菜单项。但另一方面,如果我使用oracle数据库进行菜单绑定,则不会在页面上显示菜单项。在运行时显示菜单控件空白
Sql连接
try
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
DataSet ds = new DataSet();
string connStr = "server=webserver;uid=sa;pwd=sa;database=amit;";
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "Select Menuid, subheadname, Description, ParentID, url from Menumaster where typeno like '%" + Session["user_type"].ToString().Trim() + "%' and prno is not null";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
da.Dispose();
}
ds.DataSetName = "Menus";
ds.Tables[0].TableName = "Menu";
DataRelation relation = new DataRelation("ParentChild",
ds.Tables[0].Columns["Menuid"],
ds.Tables[0].Columns["ParentID"], false);
relation.Nested = true;
ds.Relations.Add(relation);
xmlDataSource.Data = ds.GetXml();
}
catch
{
Response.Redirect("Error.aspx");
}
oracle连接
Try
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim constr As String =
System.Configuration.ConfigurationManager.ConnectionString("ConnectionString").ConnectionString
Dim ds As DataSet = New DataSet()
Using conn As New OleDbConnection(constr)
Dim str As String = "Select Menuid, subheadname,Description, ParentID,url from dtl_Menumaster where prno is not null ORDER BY MENUID"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, conn)
da.Fill(ds)
da.Dispose()
End Using
ds.DataSetName = "Menus"
ds.Tables(0).TableName = "Menu"
Dim relation As DataRelation = New DataRelation("ParentChild",
ds.Tables(0).Columns("Menuid"),
ds.Tables(0).Columns("ParentID"), True)
relation.Nested = True
ds.Relations.Add(relation)
xmlDataSource.Data = ds.GetXml()
Catch ex As Exception
End Try