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
 GridViewInsertUpdateDelete
Posted by jayanta sarkar on  1/2/2010 12:09:16 AM Category: ADO.NET
Add to my favorites
Email to friend
Error 1 The type or namespace name 'CustomersCls' could not be found (are you missing a using directive or an assembly reference?) D:\jayanta\GridViewInsertUpdateDelete\GridViewInsertEditUpdateDelete.aspx.cs 15 5 http://localhost/GridViewInsertUpdateDelete/


how to use webconfig connection sting with CustomersCls.cs

my code this type

web config code

<connectionStrings>
<add name="cnstr" connectionString="Data Source=HOME; Initial Catalog= Jayanta; Integrated Security=True"/>
</connectionStrings>

***********************
public class CustomersCls
{

private string cnstr = ConfigurationManager.ConnectionStrings["cnstr"].ToString();

private string sql;
***************************
public partial class GridViewInsertEditUpdateDelete : System.Web.UI.Page
{

CustomersCls customer = new CustomersCls(); //error in this section
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
FillCustomerInGrid();
}



Post Your Reply Post New Question

 Viewer's Reply
Class files in App_Code
Answered By Moderator1 on 1/2/2010 9:43:47 PM
Hi,

You need to place the CustomerCls file in the App_Code Directory of your solution.

To add App_Code folder to your solution, Right-Click on your Project > go to Add ASP.NET Folder > App_Code. This will add App_Code folder in your solution, then cut and paste the CustomerCls inside App_Code, then run your application.

Connection String in Web.Config file can be as follows,
<connectionStrings>
<add name="ConnectionString" connectionString="Initial Catalog=HOME;Data Source=localhost;Uid=xxsaxx;Pwd=xxpwdxx;"/>
</connectionStrings>

To access web.config file from application, do as below,
private string cnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

If you still have questions regarding this, post it here.
 
help
Answered By sarita on 12/22/2010 6:41:05 PM
public class CustomersCls
{

private string cnstr = ConfigurationManager.ConnectionStrings["cnstr"].ToString(); //error in this section
Object reference is not set to instance of an object..


private string sql;

Please help me with this code..
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
The Beginner's Guide to Joomla
Programmers Heaven C# School Book - Free 338 Page eBook