Fill: SelectCommand.Connection property has not been initialized.

Posted by Gow.Net under ASP.NET on 9/16/2012 | Points: 10 | Views : 7224 | Status : [Member] | Replies : 8
my code:


strcmd="select city_name,c_id from citys_info Where city_name like '" + strname + "%' order by city_name asc";

SqlDataAdapter dap = new SqlDataAdapter(strcmd, obj_dbconnection.objDBcon);

DataSet ds = new DataSet();
dap.Fill(ds);
return ds.Tables[0];



how to solve this please any one give me a solution

gowthaman8870226416


Responses

Posted by: Muhsinathk on: 9/17/2012 [Member] Bronze | Points: 25

Up
0
Down

Please try this

DataTable dt = new DataTable();
MySqlConnection objDBcon= new MySqlConnection(@"connection string");//tested and working
objDBcon.Open();

MySqlCommand strcmd= new MySqlCommand("select city_name,c_id from citys_info Where city_name like '" + strname + "%' order by city_name asc",objDBcon);
MySqlDataAdapter dap = new MySqlDataAdapter(strcmd);

dap.SelectCommand = strcmd;
dap.Fill(dt);
conn.Close();


Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/17/2012 [Member] Bronze | Points: 25

Up
0
Down
Please mark as answer if it helpful to you..That helps others who search the same..

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
hi Gow.net,
please open connection before command.that is only the problem.u can try like this.
con.open();
strcmd="select city_name,c_id from citys_info Where city_name like '" + strname + "%' order by city_name asc";
SqlDataAdapter dap = new SqlDataAdapter(strcmd, obj_dbconnection.objDBcon);
DataSet ds = new DataSet();
dap.Fill(ds);
return ds.Tables[0];
con.close();


Thanks & Regards
Hari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
Please mark as answer if it helpful to you..That helps others who search the same..

Thanks & Regards
Hari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikash on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
Its saying that .. 'obj_dbconnection.objDBcon' connection object doesnot belong to any SqlConnection Class.
means u have not initialized SqlConnection class.

Regards,
Vikash Pathak

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikash on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
If found interesting mark as answer............

Regards,
Vikash Pathak

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pgayath on: 9/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Please add "obj_dbconnection.objDBcon.open" above to your code or make sure your connection is open as the error is related with "Connection is not opened".

Hope this helps.

Thanks and Regards,
Gayathri P

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pgayath on: 9/18/2012 [Member] Starter | Points: 25

Up
0
Down
Please Mark As Answer if any of the reply answers u.

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response