Results 1 to 6 of 6

Thread: [RESOLVED] [02/03] Can't put together two strings, runtime error.

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    61

    Resolved [RESOLVED] [02/03] Can't put together two strings, runtime error.

    This is the offending piece of code, the boldened part is where the error occurs.
    VB Code:
    1. Dim sqlQuery As String = "INSERT INTO longdescs (bug_id, " & _
    2. "bug_when, " & _
    3. "thetext, " & _
    4. "who) " & _
    5. "VALUES ("
    6.  
    7. [b]sqlQuery &= data.Tables("ProblemTable").Rows(0).item(0).ToString & ", '"[/b]
    This is the error that I'm getting while running it.
    Code:
    System.NullReferenceException: Object reference not set to an instance of an object.
    I used New in order to create a new instance of the DataSet object so I don't understand the warning message about the object reference being not set.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Can't put together two strings, runtime error.

    Either:
    1) the dataset "data" has no table "ProblemTable" or
    2) "ProblemTable" has no data in it
    Thus, when you try to refer to it, you trigger an a null reference exception.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    61

    Re: [02/03] Can't put together two strings, runtime error.

    Quote Originally Posted by stanav
    Either:
    1) the dataset "data" has no table "ProblemTable" or
    2) "ProblemTable" has no data in it
    Thus, when you try to refer to it, you trigger an a null reference exception.
    There is such table (I'm looking at the Access DB right now) and the dataset does have values in it (I checked beforehand by taking the length of it, which was greater than 0.)

    The weird thing is that when I replaced the string "ProblemTable" with 0, it worked without a hitch.

  4. #4
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [02/03] Can't put together two strings, runtime error.

    It looks like you are missing a parenthese.

    You open it here:
    "VALUES ("

    but you don't close it.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Can't put together two strings, runtime error.

    Quote Originally Posted by YourSurrogateGod
    There is such table (I'm looking at the Access DB right now) and the dataset does have values in it (I checked beforehand by taking the length of it, which was greater than 0.)

    The weird thing is that when I replaced the string "ProblemTable" with 0, it worked without a hitch.
    You can do a quick check by running a loop to display all table names of in data.Tables(). Table(0) might not be the same Table("ProblemTable").

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    61

    Re: [02/03] Can't put together two strings, runtime error.

    Quote Originally Posted by mpdeglau
    It looks like you are missing a parenthese.

    You open it here:
    "VALUES ("

    but you don't close it.
    I close it later on in the code.

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