|
-
Aug 16th, 2007, 09:17 AM
#1
Thread Starter
Lively Member
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
-
Aug 16th, 2007, 09:47 AM
#2
Re: Help with Error
on what line is it throwing this error?
-
Aug 16th, 2007, 09:55 AM
#3
Thread Starter
Lively Member
Re: Help with Error
mytable.Load(reader)
thanks
-
Aug 16th, 2007, 09:58 AM
#4
Thread Starter
Lively Member
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
-
Aug 16th, 2007, 10:35 AM
#5
Re: Help with Error
If your problem has been solved you should mark the thread as resolved
-
Aug 16th, 2007, 08:27 PM
#6
Re: Help with Error
Can I also recommend that instead of this:
C# Code:
DbConnection conn = myFactory.CreateConnection();
conn.ConnectionString = connectionString;
using (conn)
{
you do this:
C# Code:
using (DbConnection conn = myFactory.CreateConnection())
{
conn.ConnectionString = connectionString;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|