Listing from databaseresult (ms sql) in ASP

Results 1 to 2 of 2

Thread: Listing from databaseresult (ms sql) in ASP

  1. #1
    Join Date
    Dec 1969

    Default Listing from databaseresult (ms sql) in ASP

    I have a problem with listing from databaseresult (ms sql) in ASP. <BR>The problem is:<BR><BR>I have a table; “article”, with several articles. These articles are linked to states, sometimes more than one state. So I created the table “article_state” and a table with all the states, called “states”.<BR><BR>In the publishing tool I made I can select to relate the article to several states when I make the article. The problem is when I edit the article. I want to list up the states with checkboxes, and show if the state is already selected/checked.<BR><BR>Any of you that could suggest how I can do that with the db-setup I have?<BR>Or how I sould set this up?<BR><BR>Thanx :)<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Listing from databaseresult (ms sql) in ASP

    I would really call "article_state" just article since it has nothing to do with states...<BR>Also just a small thing: It is a good thing to have some "naming convention". So you either call your tables STATES and ARTICLES or STATE and ARTICLE. If some are plural and some are not, you will find yourself looking up the exact name from time to time (And thus wasting time).<BR><BR>Table: article<BR>ID<BR>Name<BR><BR>Table: state<BR>ID<BR>Article_Id<BR>Desc<BR><BR>SELECT,, state.desc FROM article, state WHERE<BR><BR>Dim LastArticle As String = ""<BR>Dim StateList As CheckBoxList<BR><BR>Do While SqlReader.Read()<BR> If Not SqlReader("name").Equals(LastArticle) Then<BR> LastArticle = SqlReader("name")<BR> StateList = FindControl("states" & SqlReader("id"))<BR> End If<BR><BR> StateList.Items.Add(SqlReader("desc"))<BR>Loop<BR> <BR>This code should add all states of an article to the CheckBoxList called "statesX" where X is the article number.<BR><BR>If you want to do this for just one article, you just have to add a where clause to your select and remove the If clause in the loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts