Results 1 to 4 of 4

Thread: [RESOLVED] System.NullReferenceException: Object reference not set to an instance of an object

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Resolved [RESOLVED] System.NullReferenceException: Object reference not set to an instance of an object

    i need to isnert in database and i have query liike that

    Code:
     str_attend = "insert into Attendees([Userid],[Attendees_name],[Attendees_telephone],[Attendees_Email] )values  (" & userid & " ," & arr(0).ToString() & " , " & arr(1).ToString() & " , " & arr(3).ToString() & " )"
    all values hold values in insert statment non of of them is null.

    but it gives me an exception on insert statment .
    There is no achievement without goals

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: System.NullReferenceException: Object reference not set to an instance of an obje

    First up, don't use string concatenation to insert variables into SQL code. Use parameters instead. Follow the Blog link in my signature and check out my post on ADO.NET Parameters.

    That won;t help you with the immediate issue though. When you get a NullReferenceException is means that you are trying to access a member of an object that doesn't exist. To find out exactly where the issue is, debug your code. When the exception is thrown, test every expression that precedes a dot. When you find one that is Nothing, that's your issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: System.NullReferenceException: Object reference not set to an instance of an obje

    Now we can't get much of this code can we?
    Your problem is more likely to be on the insert code u use.
    Please post some code for inserting.

    Jm is faster as usual :P
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: System.NullReferenceException: Object reference not set to an instance of an obje

    yes i converted like this

    str_attend = "insert into Attendees (Userid, Attendees_name, Attendees_telephone, Attendees_Email) " & _
    "VALUES (" & userid & _
    ", '" & arr(0).ToString() & _
    "', '" & arr(1).ToString() & _
    "', '" & arr(0).ToString() & "')"

    and its working fine
    There is no achievement without goals

Tags for this Thread

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