Results 1 to 15 of 15

Thread: [RESOLVED] simple datatable select statment

  1. #1

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41

    [RESOLVED] simple datatable select statment

    Ok this is overly simple, but driving me crazy. Any thoughts are much appreciated.


    Dim q As String
    dim ro as datarow
    'tbliptval is a public datatable

    q = "CID = " & Process_cid & " And Name = '" & varname & "'"
    Try
    ro = tblIptVal.Select(msg)(0)
    Catch e As Exception
    MsgBox(e.ToString)
    End Try

    The query q should return one record, and does when i manually enter the sql.

    Any thoughts? ahhhhhhhhh!
    Last edited by SeaCapnJ; Jun 17th, 2004 at 03:13 PM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Not sure what you're trying to do. If q is supposed to be part of your SQL, where do you add it to anything? In the posted code it doesn't serve a purpose.

  3. #3

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    Does this explain it better, I assigned the string to q to help in debugging. Any thoughts? thanks for the response.


    VB Code:
    1. Try
    2.      ro = tblIptVal.Select("CID = " & Process_cid & " And Name = '" & varname & "'")(0)
    3.      process_UDID = ro("UDID")
    4.            
    5.      If Not ro.IsNull("UDID") Then
    6.           processSourceID = ro("PSID")
    7.      End If
    8. catch e as exception
    9.             MsgBox(e.ToString)
    10. End Try

  4. #4
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Doesn't Select return an Array of DataRows, not a single DataRow?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  5. #5
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    Originally posted by SeanGrebey
    Doesn't Select return an Array of DataRows, not a single DataRow?
    It does indeed.

  6. #6

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    Yah, it does.

    That's why I am grabbing the table at index 0.

    ro = tblIptVal.Select(msg)(0)

    the error message it gives is something like:

    "filter expression "0" does not evaluate to a boolean term." So maybe that is where im going wrong.

  7. #7
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    Originally posted by SeaCapnJ
    Yah, it does.

    That's why I am grabbing the row at index 0.
    But you've declared "ro" as a datarow object - not an array of objects of type datarow.
    Code:
    Dim ro() as DataRow

  8. #8

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    I guess I didnt edit that response quick enough.

    but ill play with it, maybe it is the indexing ?

  9. #9

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    Dim r As DataRow()

    r = tblIptVal.Select(msg)

    Tried that, Got the same error message about indexing at 0.
    Man I have written 100's of these, what am I doing wrong here? grr!

  10. #10
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    Post your current code so we're not talking past one another.

  11. #11

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    I get an index out of range message, which tends leads me to believe that the query is resulting in null. However, when I manually enter the query, I get a record.

    VB Code:
    1. Dim ro As DataRow()
    2.         Dim q As String
    3.  
    4.         q = "CID = " & Process_cid & " And Name = '" & varname & "'"
    5.  
    6.         Try
    7.             MsgBox(q)
    8.             ro = tblIptVal.Select(q)
    9.             process_UDID = ro(0)("udid")
    10.            
    11.         Catch e As Exception
    12.             MsgBox(e.ToString)
    13.         End Try

  12. #12

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    Well the problem is with varname, for some reason when I type it in, its not exactly like what I see. I do not have the answer to what is wrong, but I do not understand why the string that I see and the string that I type are not the same.

  13. #13
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    How are they different?

  14. #14
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    varname doesn't have a single quote in it does it?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  15. #15

    Thread Starter
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41
    Always the simple solution. Why could I find the record I was looking for? Because I was deleting that record in a forum i wrote months ago. Bah!

    Thanks so much for the help guys.

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