Solved

asp.net function to return dataset

Posted on 2009-07-12
3
263 Views
Last Modified: 2012-05-07
Hello Experts

I am trying to store some pattern in the database table using the data from the function which returns the dataset.

I wanted to loop through all the records from this dataset and assign the value to the stringcollection variable.

Please can someone advise how I can go about looping through the rows I get from this dataset, once I get the column values I can then assign them to the string collection.

Please see the code below, hope someone may understand what I am trying to do here?

Thanks
S

0
Comment
Question by:newbie27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Author Comment

by:newbie27
ID: 24834354
please see the code below
ds = RegistrationPersonalisedClassics.GetPatternIDAndPatternName(TemplateID)
 
 
Registration.Patterns.Add(FIRST_PATTERN_NAME_GOES_HERE + "\n" + txtPatternOne.Text)
Registration.Patterns.Add(second_PATTERN_NAME_GOES_HERE + "\n" + txtPatternTwo.Text)
Registration.Patterns.Add(third_PATTERN_NAME_GOES_HERE + "\n" + txtPatternThree.Text)
Registration.Patterns.Add(fourth_PATTERN_NAME_GOES_HERE + "\n" + txtPatternFour.Text)
Registration.Patterns.Add(fifth_PATTERN_NAME_GOES_HERE + "\n" + txtPatternFive.Text)
Registration.Patterns.Add(sixth_PATTERN_NAME_GOES_HERE + "\n" + txtPatternSix.Text)
 
 
 
 
Public Shared Function GetPatternIDAndPatternName(ByVal TemplatedID As Integer) As DataSet
 
        
        Dim dt As New Data.DataTable("Pattterns")
        Dim dr As Data.DataRow
        Dim dbConn As SqlConnection
        Dim SQL As String
        Dim dbComm As SqlCommand
        Dim dbRead As SqlDataReader
 
 
        Try
                        dbConn.Open()
            SQL = "SELECT * " & _
                  "FROM PC_Pattern " & _
                  "WHERE TemplateID=" & TemplatedID
 
            dbComm = New SqlCommand(SQL, dbConn)
            dbRead = dbComm.ExecuteReader()
 
            dt.Columns.Add(New DataColumn("PatternID", GetType(Integer)))
            dt.Columns.Add(New DataColumn("PatternName", GetType(String)))
           
            While dbRead.Read
                dr = dt.NewRow
                dr.Item("PatternID") = dbRead("PatternID")
                dr.Item("PatternName") = dbRead("PatternName")
                dt.Rows.Add(dr)
            End While
 
            ds.Tables.Add(dt)
 
            Return ds
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
 
 
data
=====
patterid pattername
1	 Alice	
2	 The White Rabbit	
3	 The Queen of Hearts	
4	 The King of Hearts	
5	 The Mad Hatter	
6	 The Cheshire Cat	

Open in new window

0
 
LVL 19

Accepted Solution

by:
daveamour earned 400 total points
ID: 24837235
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 24837850
Here is an example of looping through the dataset.


For i as integer = 0 to dSet.Tables(0).Rows.Count - 1
    str &= "Name: " & dSet.Tables(0).Rows(i).Item(0) & ", Address: " & dSet.Tables(0).Rows(i).Item(1) & VBCRLF
Next

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question