Results 1 to 6 of 6

Thread: Question on dataset data retrieval

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Question on dataset data retrieval

    Is there an alternative to:

    ds.Tables("TableName").Rows(0)(2).ToString()

    That I can use the field name instead? Or should I just only pull the 7 or so fields in my sql statement and use the .rows parameters?

    Thanks

  2. #2
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: Question on dataset data retrieval

    How are you creating your dataset. If you are using visual studio you can generate strongly bound datasets that allow you to reference rows and columns through code.

    I suggest you look into this. Basically the line of code you wrote would become

    objdsMyDataSet.MyTable(0).MyColumn

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Question on dataset data retrieval

    Quote Originally Posted by The_Duck
    How are you creating your dataset. If you are using visual studio you can generate strongly bound datasets that allow you to reference rows and columns through code.

    I suggest you look into this. Basically the line of code you wrote would become

    objdsMyDataSet.MyTable(0).MyColumn

    This is how I am creating the set:

    VB Code:
    1. Try
    2.             ds.Clear()
    3.             sSQL = "SELECT * FROM Style WHERE Style_Number = @StyleNumb"
    4.  
    5.             da = New SqlClient.SqlDataAdapter(sSQL, conn)
    6.             da.SelectCommand.Parameters.Add("@StyleNumb", stStyleNumb)
    7.  
    8.             conn.Open()
    9.  
    10.             da.Fill(ds, "Style")
    11.             If ds.Tables("Style").Rows.Count <> 0 Then
    12.                
    13.                 lblDescription.Text = ds.Tables("Style").Rows(0)(4) 'would like to replace this line by using the actual column name.
    14.              Else
    15.  
    16.             End If
    17.  
    18.         Catch ex As Exception
    19.             'Handle Error
    20.         Finally
    21.             If conn.State = ConnectionState.Open Then
    22.                 conn.Close()
    23.             End If
    24.         End Try

  4. #4
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: Question on dataset data retrieval

    Are you using visual studio?

    Try adding an item called a DataSet.

    That code you posted does not show how you create your dataset, only how you clear and fill it!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Question on dataset data retrieval

    Quote Originally Posted by The_Duck
    Are you using visual studio?

    Try adding an item called a DataSet.

    That code you posted does not show how you create your dataset, only how you clear and fill it!
    Sorry, Yes I am using visual studio, here is where I create the dataset:

    VB Code:
    1. Private da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter
    2.     Private ds As New DataSet

  6. #6
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    Re: Question on dataset data retrieval

    Try adding a dataset to your project then!

    (From Memory)
    Right Click on your Project
    Choose Add New Item
    Choose a dataset from the lists

    What this allows you to do is define your dataset using xml (the designer will help).

    Even better if add your database as a datasouce, you can drag your table onto the dataset and watch it create all the columns for you!

    Even better than that it will create (when you save the dataset) all of the code necessary to access that datatable!

    Good Luck!

Posting Permissions

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



Click Here to Expand Forum to Full Width