Friday, March 16, 2012

Looping through Database?

Hi,
I'm new to ASP.NET and have just strated using VS 2003 what I want to know
is how I do a loop through a table in a database? I would be grateful for an
y feedback!
I'm trying to build a menu programatically! I want to use a table to build a
piece of code similar to this:
...: CODE :...
Dim submenu1 As New skmMenu.MenuItem("<img src="http://pics.10026.com/?src="images/menublip.gif"" align
=""absmiddle"">Home", "")
submenu1.SubItems.Add(New skmMenu.MenuItem("Sub Item 1", "page1.html"))
submenu1.SubItems.Add(New skmMenu.MenuItem("Sub Item 2", "page2.html"))
Dim submenu3 As New skmMenu.MenuItem("Sub Item 3 ->", "")
submenu3.SubItems.Add(New skmMenu.MenuItem("Sub Item 3 - 1", "page1.html"))
submenu3.SubItems.Add(New skmMenu.MenuItem("Sub Item 3 - 2", "page2.html"))
submenu1.SubItems.Add(submenu3)
submenu1.SubItems.Add(New skmMenu.MenuItem("Sub Item 4", "page4.html"))
submenu1.SubItems.Add(New skmMenu.MenuItem("Sub Item 5", "page5.html"))
submenu1.SubItems.Add(New skmMenu.MenuItem("Sub Item 6", "page6.html"))
Menu1.Items.Add(submenu1)
Dim submenu2 As New skmMenu.MenuItem("<img src="http://pics.10026.com/?src="images/menublip.gif"" align
=""absmiddle"">Office", "")
submenu2.SubItems.Add(New skmMenu.MenuItem("Sub Item 1", "page3.html", "tool
tip1"))
submenu2.SubItems.Add(New skmMenu.MenuItem("Sub Item 2", "page4.html", "tool
tip2"))
Menu1.Items.Add(submenu2)
.....................
In the table I would have the following fields
-menuid
-name
-url
-level
I would be really really grateful if someone could give me some advice on ho
w to achive this!
ThanksHello,
You have not said what Database you're using so I'll just give you the
looping code, you'll need to populate a DataSet object for this to
work: -
foreach(DataRow DR in DS.Tables[0])
{
myMenuId = DR["menuid"].ToString();
}
Does this help?
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
Hi Phil,
Thanks for the reply! I'm using SQL 2000 Server!
I presume I can just use the tools in VS to create my OLE connection and the
n create a dataset! How do I then link this into the loop?
Thanks
for each(DataRow DR in DS.Tables[0])
{
myMenuId = DR["menuid"].ToString();
}
Hi,
Take a look at this page: -
http://msdn.microsoft.com/library/d...dataadapter.asp
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com

0 comments:

Post a Comment