Answered by:
ExecuteReader: Connection property has not been initialized

Question
-
ExecuteReader: Connection property has not been initialized
write me code in c#
Mr.GMKREDDY- Moved by litdev Friday, August 19, 2011 7:10 PM Not a SmallBasic question (From:Small Basic)
Friday, August 19, 2011 8:59 AM
Answers
-
Hi,
could you please tell me, how you found your way into this forum when you was looking for a forum? I am just wondering a little, because this forum covers Small basic (http://smallbasic.com).
All you need and ask for can be found on MSDN (including a lot of code samples!):
- ADO.Net ist documented on MSDN at http://msdn.microsoft.com/en-us/library/h43ks021(v=VS.100).aspx - if you want to access databases you should spend some time reading there.
- The following links document the classes/methods that you are looking for:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx
http://msdn.microsoft.com/en-us/library/9kcbe65k.aspxSo just follow the links and read a little. C# examples are on these pages, too. And for more c# related questions: Think about using some better forum like http://social.msdn.microsoft.com/Forums/de-DE/Vsexpressvcs/threads
And your problem seems to be, that you need an open connection set inside the command. You need to connect to a database first so you can execute a command on it. Without that, the program cannot know where to execute the command.
I hope that helped a little.
With kind regards
Konrad
- Marked as answer by Lie YouModerator Friday, August 26, 2011 5:12 AM
Friday, August 19, 2011 11:35 AM -
Here is an example about ExecuteReader for your reference:
using (SqlConnection connection = new SqlConnection( connectionString)) { <strong>connection.Open();//connection must be initialized</strong> SqlCommand command = new SqlCommand(queryString, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(String.Format("{0}", reader[0])); } }
Here is the connection string:string connectionstring =@"Data Source=.\;Initial Catalog=test;Integrated Security=True"
For more connection string:Hope it helps.
Best Regards,
Rocky Yue[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Lie YouModerator Friday, August 26, 2011 5:12 AM
Tuesday, August 23, 2011 5:33 AMModerator
All replies
-
Hi,
could you please tell me, how you found your way into this forum when you was looking for a forum? I am just wondering a little, because this forum covers Small basic (http://smallbasic.com).
All you need and ask for can be found on MSDN (including a lot of code samples!):
- ADO.Net ist documented on MSDN at http://msdn.microsoft.com/en-us/library/h43ks021(v=VS.100).aspx - if you want to access databases you should spend some time reading there.
- The following links document the classes/methods that you are looking for:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx
http://msdn.microsoft.com/en-us/library/9kcbe65k.aspxSo just follow the links and read a little. C# examples are on these pages, too. And for more c# related questions: Think about using some better forum like http://social.msdn.microsoft.com/Forums/de-DE/Vsexpressvcs/threads
And your problem seems to be, that you need an open connection set inside the command. You need to connect to a database first so you can execute a command on it. Without that, the program cannot know where to execute the command.
I hope that helped a little.
With kind regards
Konrad
- Marked as answer by Lie YouModerator Friday, August 26, 2011 5:12 AM
Friday, August 19, 2011 11:35 AM -
Here is an example about ExecuteReader for your reference:
using (SqlConnection connection = new SqlConnection( connectionString)) { <strong>connection.Open();//connection must be initialized</strong> SqlCommand command = new SqlCommand(queryString, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(String.Format("{0}", reader[0])); } }
Here is the connection string:string connectionstring =@"Data Source=.\;Initial Catalog=test;Integrated Security=True"
For more connection string:Hope it helps.
Best Regards,
Rocky Yue[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked as answer by Lie YouModerator Friday, August 26, 2011 5:12 AM
Tuesday, August 23, 2011 5:33 AMModerator