Results 1 to 6 of 6

Thread: Datatable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Datatable

    i gurus

    I have a select statement and it will go to a datatable object, I would like to do the following

    textbox1.text=datatable(first field value)
    textbox2.text=datatable(second field value)
    textbox3.text=datatable(third field value)

    please help and thanks a bunch

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Datatable

    How do you intend to decide which row is being shown?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: Datatable

    shaggy

    thanks for jumping in, the result from the select statement should only be one row of information, and is in here where I need the help.

    Thanks again a bunch

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Datatable

    If there will only be one row, then access the first row in the DataTable via the Rows property. Then access the fields of said row by either their column indexes or column names.

    May I also suggest that you upgrade to at least VS2008?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Datatable

    What ForumAccount said is the way I would do it. I would also use the field names rather than the field ordinals, simply because the field names remain ok even if you change your SQL statement to include more fields, or include them in a different order.

    It would look something like this:

    TextBox1.Text = YourDatatable.Rows(<the row you want>).Items("<Your item name here>").ToString

    That way, you could build this into a sub that took the row number as an argument, and you could use it to navigate through the rows, if that was of interest.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: Datatable

    thanks F/S

    So in my case this will be

    textbox1.text=datatable.rows(0).items("First").tostring
    textbox2.text=datatable.rows(0).items("last").tostring

    I am ok in my line

    Thanks again

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