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
 Regarding Database Connection using class file
Posted by Yasmine Banu on  3/28/2013 7:07:05 AM Category: C#
Add to my favorites
Email to friend
This is class file code:
public class clssqlcon
{
public string constr;
public clssqlcon()
{
constr = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
}
}
But I can't able to access "constr" variables in code behind file
This is my code behind file code:
clssqlcon user = new clssqlcon();
SqlConnection con = new SqlConnection(constr);

Post Your Reply Post New Question

 Viewer's Reply
Create object to Class
Answered By Moderator1 on 3/28/2013 8:17:23 AM
Hi,

You are wrong. You need to access as below
clssqlcon user = new clssqlcon();
SqlConnection con = new SqlConnection(user.constr);

Note the change is 'user.constr'
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
Many .NET teams are underperforming, is yours?
The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks & Hacks - Free 156 Page Preview