Results 1 to 4 of 4

Thread: dataset 101

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    11

    dataset 101

    Hi all

    Just doing my first VB.net project for Uni and have come a bit stuck using a dataset...if anybody has some advice I would appreciate it.

    I have a form that has a dataAdapter on it (OleDbDataAdapter3) which I have configured with a WHERE statement based on ItemID which I get from a text box. I want to get the other data from the dataset (dataset11) such as the description field, the title etc. I can do this by binding a textbox (did that to make sure the DataAdapter WHERE statement was working...however I was wondering if there is a way to use the dataset data straight into a variable. I tired the following...

    strDescription = Me.txtDescription.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSet11, "Items.Description"))

    but I get the error message saying "this expression does not produce a value". Is there an easy way to get the value from a dataset? I can post more code if it's helpful...

    thanks in advance

    cameron

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: dataset 101

    Just by looking at the names of the dataset and dataadapter, I'm pretty sure you're using the drag and drop method of creating your datasets. I am not very familiar with that method, and neither are a lot of the members here. We prefer handcoding it.

    Here's a simple example with a sqldataadapter:

    VB Code:
    1. Dim da As SqlClient.SqlDataAdapter
    2.         Dim strSQL As String
    3.         Dim strConn As String
    4.  
    5.         strConn = "Data Source=(local); Initial Catalog=Northwind; User ID=sa;"
    6.         strSQL = "SELECT * FROM Products"
    7.  
    8.         ds = New DataSet
    9.         Try
    10.             da = New SqlClient.SqlDataAdapter(strSQL, strConn)
    11.             da.Fill(ds, "Products")
    12.             TextBox1.text = ds.Tables(0).Rows(0).Item(4).ToString()
    13.  
    14.         Catch ex As Exception
    15.             MessageBox.Show(ex.Message.ToString)
    16.  
    17.         End Try

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    11

    Re: dataset 101

    Cheers

    it's the drag and drop that is making the whole thing hard I think....it's the way the lecturer reccomended doing it...however just looking at your code it's clearer what is actually happening so think I will make the switch to handcoding

    thanks for the assistance
    cameron

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: dataset 101

    That's why I reccommended this method. It helps you understand what actually is going on. I do not understand why your lecturer would reccommend this, but hey, to each his own.

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