AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Database Manipulations in a Class File
Posted by Swetha Hjii on  8/11/2008 12:17:41 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi,

Can anyone let me know how to create a database connection in a class file?


Post Your Reply Post New Question

 Viewer's Reply
SqlConnection in Class File
Answered By Moderator1 on 8/16/2008 2:35:13 AM
In your class file,

Using System.Data.SqlClient;


public SqlConnection myconn;

public void OpenConnection()
{
myconn=new SqlConnection("Your Connection String");
myconn.Open();
}

public void CloseConnection()
{
myconn.Close();
}

Create an instance to your class file. then you can access the myconn object.
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
The Art & Science of JavaScript - Free 100 Page Preview!
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview