AspdotnetCodes.com
Voted 'Best ASP.NET Host' for 2008 – DiscountASP.NET
 
Articles Subscribe for our Articles Updates
Books
Resources
Downloads
Free Tech Magazines
Archives
Softwares
Newsletter
Suggest Us
Link to Us
 Best Syntax to Open a SqlConnection in Asp.Net 2.0
Posted by Moderator1 on  1/4/2008 2:48:15 AM 1294 Views
 
Here is the best method to open a SqlConnection in Asp.Net 2.0

using (SqlConnection conn = new SqlConnection("YourConnectionString"))
{
using (SqlCommand cmd = new SqlCommand("YourCommandString", conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}

The above syntax opens and closes the connection along with the SqlCommand itself. Every effective in case of any error occurs in database manipulations.

Post New Tips/Tricks View all Tips/Tricks

Sponsored by