Results 1 to 6 of 6

Thread: Help with Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Help with Error

    Hi Everyone,

    I have this piece of code that keeps throwing an error. I have no idea why it is throwing this error. The error being thrown is:

    Object not set to instance of an object

    Code:
     
                DbConnection conn = myFactory.CreateConnection();
                conn.ConnectionString = connectionString;
                using (conn)
                {
                    conn.Open();
                    DbCommand cmd = conn.CreateCommand();
                    cmd.CommandText = sqlStatement;
                    cmd.CommandType = CommandType.Text;
                    DbDataReader reader = cmd.ExecuteReader();
                    myTable.Load(reader);
                    
                }
                return myTable;

    Thanks for all the help

    -zd

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Help with Error

    on what line is it throwing this error?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: Help with Error

    mytable.Load(reader)
    thanks

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: Help with Error

    Thanks Everyone for all the help. I figured it out. The Data table that I was passing into this method had been set to null previously. I had to "new" it up.

    Thanks Atheist for the help.



    -zd

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Help with Error

    If your problem has been solved you should mark the thread as resolved
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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

    Re: Help with Error

    Can I also recommend that instead of this:
    C# Code:
    1. DbConnection conn = myFactory.CreateConnection();
    2. conn.ConnectionString = connectionString;
    3. using (conn)
    4. {
    you do this:
    C# Code:
    1. using (DbConnection conn = myFactory.CreateConnection())
    2. {
    3.     conn.ConnectionString = connectionString;
    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

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