?
Solved

SQL connection object in 2005

Posted on 2006-06-04
4
Medium Priority
?
290 Views
Last Modified: 2010-04-16
I've been using 2003 for a while and have recently upgraded to 2005.  I can't seem to fine the sqlconnection object in the tool box, where is it??

0
Comment
Question by:Steve7423
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:aaronfeng
ID: 16827826
The way to do it in VS 2005 is to add a new data source in the Data menu.  It will ask you for your connection string and other info in the wizard.  For more info: http://www.ftponline.com/vsm/2005_12/magazine/features/rjennings/


Cheers,

Aaron
http://aaronfeng.blogspot.com
0
 

Author Comment

by:Steve7423
ID: 16827940
ok. so the way I see it is that data controls are created via wizards rather than from objects in the tool box like in 2003.

could you show me the way in which you would use this data object and some code to access the data.

0
 

Author Comment

by:Steve7423
ID: 16827943
Also, how is this done in code??  without the use of the wizard.
0
 
LVL 5

Accepted Solution

by:
aaronfeng earned 600 total points
ID: 16827977
If all you want to create a SqlConnection you can just do it in the code like this:

SqlConnection conn = new  SqlConnection(/* Add the connection string here */);

SqlDataReader reader = null;

try {
   conn.Open();
   SqlCommand cmd = new SqlCommand("SELECT* FROM Students", conn);
   reader= cmd.ExecuteReader();
   // do stuff with your reader here.
}
finally {
  if (reader!= null) rdr.Close()
  if (conn != null) conn.Close();
 }

Cheers,

Aaron
http://aaronfeng.blogspot.com
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question