Results 1 to 7 of 7

Thread: Find specific value in dataset???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84

    Find specific value in dataset???

    Hi, I'm here again.

    I have a datatable with the following columns:
    UserID (pk, autonumber)
    UserName (text)
    RightsID (number)


    I fill a dataset (DSUsers) with the values of this datatable and now I want to find a specific value of this dataset: the RightsID of the first UserID in the table.

    I tried the following code:

    Dim UserRights as Integer
    UserRights = DSUsers.Tables("tblUsers").Rows(0)("RightsID")

    But I constantly get the value '0' while it should be '2' because thats the actual value in the database.

    Is my selection code wrong?

    thanks

    TOm

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    dim dr2 as datarow
    Dim UserRights as Integer
    dr2 = DSUsers.Tables.Item("tblUsers").Rows(0)
    UserRights = dr2("RightsID")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    Thanks,

    I tried your suggestion but I'm still getting the same resultvalue: 0

    Here's my code:

    SQLUser = "SELECT * FROM tblUsers WHERE UserName=" & user
    DAUsers = New OleDbDataAdapter(SQLUser, DataConnectionUsers)
    DataConnectionUsers.Open()
    DAUsers.Fill(DSUsers, "tblUsers")
    DataConnectionUsers.Close()

    NumberUsers = DSUsers.Tables("tblUsers").Rows.Count()


    dr2 = DSUsers.Tables.Item("tblUsers").Rows(1)
    UserRights = dr2("UserID")

    I really do't understand what's going wrong.


    TOm

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    rows index starts at zero. try

    dim temp as integer
    temp = DSUsers.Tables(0).Rows(0).Item("RightsID")
    Last edited by nswan; Dec 16th, 2003 at 08:43 AM.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    thanks nswan

    I tried your suggestion but I still get the same result. I also doublechecked if the dataset contains values and the answer is yes because I filled up a datagrid with the values.

    Any Ideas?

    Tom

  6. #6
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    i edited it a couple of times. have you tried the latest one?
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Location
    Europe, Belgium
    Posts
    84
    yes, I tried it.

    In attachment you can find the result of the datagrid (.jpg).

    Here you can see the code


    SQLUser = "SELECT * FROM tblUsers"
    DAUsers = New OleDbDataAdapter(SQLUser, DataConnectionUsers)
    DataConnectionUsers.Open()
    DAUsers.Fill(DSUsers, "tblUsers")
    DataConnectionUsers.Close()


    Me.DataGridUsers.DataSource = DSUsers
    Me.DataGridUsers.DataMember = "tblUsers"

    dr2 = DSUsers.Tables.Item("tblUsers").Rows(0)
    UserRights = dr2("RightsID")


    any ideas?

    Tom
    Attached Images Attached Images  

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