Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
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

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

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)

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

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,
<add name="ConnectionString" connectionString="Initial Catalog=HOME;Data Source=localhost;Uid=xxsaxx;Pwd=xxpwdxx;"/>

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.
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
Backup and Recovery Best Practices for Microsoft SQL Server 2005
Simply SQL - Free 111 Page Preview!
Introduction to Web Applications Development