Error : "Fill: SelectCommand.Connection property has not been initialized." Error : "Fill: SelectCommand.Connection property has not been initialized." asp.net asp.net

Error : "Fill: SelectCommand.Connection property has not been initialized."


Change the line

MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins");

To

MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins", conn);

And it should work.

Alternatively assign conn to the cmd.Connection property.

The problem with your code is that you never assign a connection to the command, hence the error saying that the connection is not initialized.


Try This

MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins",conn);

or

MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins");cmd.Connection=conn;


I got also this problem. after search the problem found that the object of connection that i have provide SqlDataAdapter is not Initialize so the connection passed as null