scribbles on my second haven

Fill: SelectCommand.Connection property has not been initialized.

Posted by: glique on: May 20, 2009

I got this error on the program I am creating. After reading some forums and same problems on the net, I’ve finalyy figured out what the problem is..

The errors appears when I try to get records from the database. The code looks like:

SqlCommand cmd = new SqlCommand();

cmd.CommandType = CommandType.Text;
cmd.CommandText = “SELECT * FROM ProfileTable ORDER By MemberNo;”;

da = new SqlDataAdapter();
da.SelectCommand = cmd;

ds = new DataSet();
da.Fill(ds, “ProfileTable”);

what I missed out was this line:

cmd.Connection = cn;

Connection was not initialized. OK.

The code now looks like:

SqlCommand cmd = new SqlCommand();

cmd.Connection = cn;

cmd.CommandType = CommandType.Text;
cmd.CommandText = “SELECT * FROM ProfileTable ORDER By MemberNo;”;

da = new SqlDataAdapter();
da.SelectCommand = cmd;

ds = new DataSet();
da.Fill(ds, “ProfileTable”);

2 Responses to "Fill: SelectCommand.Connection property has not been initialized."

cmd.CommandType = CommandType.Text;
cmd.CommandText = “SELECT * FROM ProfileTable ORDER By MemberNo;”;

siyet. nosebleed. anong linggawahe to?

Thanx man… I missed the line….

You saved my time…..

Leave a Reply

lique now scribbling!

IKAW! OO IKAW! PANO KA KAYA NAPADPAD SA PAHINANG ITO NG WEB? anyways, ang site na ito ay tirahan ng mga kwento ng buhay, halo-halong mga imahinasyon at mga pala-isipan ng inyong lingkod. nasasayo kung babasahin mo ang aking mga posts.
oops. dont porget the comment! salamats ng marami! GodBless. Enjoy the site.
this is me. my name is Lique || From down down south || Tatak ala eh!|| Christian|| I.Ro.Fo.Je :: I Rock For Jesus || CBA. || Writing || Capturing moments|| Photography || Literature || Leader || Events Organizer

Mga Napadpad

  • 14,039 cliques

BANGON KABATAAN!

Proudly Pinoy

Proudly Pinoy!

Let’s all HELP IGGY!

free counters

Mga Napadpad

?!@#$#%^&*

Track me

May 2009
S M T W T F S
« Apr   Jun »
 12
3456789
10111213141516
17181920212223
24252627282930
31  
View Verse of the Day