Answered by:
ExecuteScalar: Connection property has not been initialized.

Question
-
User1469062072 posted
hi
i have this erroer
ExecuteScalar: Connection property has not been initialized.
when i excute this qury:
cmd.CommandText = "select PID from Reservation where username='" + Session["username"].ToString() + "' ";string str = cmd.ExecuteScalar().ToString();string cmd1 = " select Pname, Gender , Status , Medicin, Comment , Bill from Report where PID = '"+Convert.ToInt32( str)+ "'";cmd.CommandText = "select PID from Reservation where username='" + Session["username"].ToString() + "' ";
string str = cmd.ExecuteScalar().ToString();
string cmd1 = " select Pname, Gender , Status , Medicin, Comment , Bill from Report where PID = '"+Convert.ToInt32( str)+ "'";
Wednesday, December 23, 2009 2:28 PM
Answers
-
User-1360095595 posted
It sounds like you haven't associated a Connection with the command. You need to associate it via the constructor, or via the Connection property.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 23, 2009 2:47 PM -
User1716267170 posted
Hi bian,
I think MetalAsp.Net is right. You missed the information for connection object. Please check this sample for details:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 27, 2009 9:47 PM
All replies
-
User-1360095595 posted
It sounds like you haven't associated a Connection with the command. You need to associate it via the constructor, or via the Connection property.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 23, 2009 2:47 PM -
User1469062072 posted
hi
can you explain more i don't understand you ????!!!!
Thursday, December 24, 2009 12:32 AM -
User1716267170 posted
Hi bian,
I think MetalAsp.Net is right. You missed the information for connection object. Please check this sample for details:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 27, 2009 9:47 PM