?
Solved

when i build my project it give an error  what i have pasted .

Posted on 2009-02-11
1
Medium Priority
?
262 Views
Last Modified: 2013-12-17
Error:

Error      1      The name 'connStr' does not exist in the current context      D:\3-TierArchitecture\App_Code\3-Tier\DAL\PersonDAL3.cs      36      48      D:\3-TierArchitecture\
Error      2      The name 'connStr' does not exist in the current context      D:\3-TierArchitecture\App_Code\3-Tier\DAL\PersonDAL3.cs      72      48      D:\3-TierArchitecture\
Error      3      The name 'connStr' does not exist in the current context      D:\3-TierArchitecture\App_Code\3-Tier\DAL\PersonDAL3.cs      105      48      D:\3-TierArchitecture\
Error      4      The name 'connStr' does not exist in the current context      D:\3-TierArchitecture\App_Code\3-Tier\DAL\PersonDAL3.cs      139      48      D:\3-TierArchitecture\

<configuration>
	<appSettings/>
	<connectionStrings>
 <add name="TutTestConn" connectionString="Data Source=TAPAN\SQLEXPRESS;Initial Catalog=ThreeTier;Integrated Security=True"
   providerName="System.Data.SqlClient" /> 
 </connectionStrings>
 
===========
 
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
 
/// <summary>
/// Summary description for PersonDAL
/// </summary>
public class PersonDAL3
{
    string ConnStr = ConfigurationManager.ConnectionStrings["TutTestConn"].ConnectionString;
    public PersonDAL3()
	{
		//
		// TODO: Adconstructor logic here
		//
	}
    ///<summary>
    ///Used to insert records into database
    ///</summary>
    ///<param name="firstName"></param>
    ///<param name="lastname"></param>
    ///<param name="age"></param>
    ///<returns></returns>
    ///
 
    public int Insert(string firstName, string lastName, int age)
    {
      
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand dCmd = new SqlCommand("InsertData", conn);
        dCmd.CommandType = CommandType.StoredProcedure;
 
        try
        {
            dCmd.Parameters.AddWithValue("@FirstName", firstName);
            dCmd.Parameters.AddWithValue("@LastName", lastName);
            dCmd.Parameters.AddWithValue("@Age", age);
        }
        catch
        {
            throw;
        }
        finally
        {
            dCmd.Dispose();
            conn.Close();
            conn.Dispose();
        }
       
 
    }
 
    ///<Summary>
    ///Update record into database
    ///</Summary>
    ///<param name="personID"></param>
    ///<param name="firstname"></param>
    ///<param name="lastname"></param>
    ///<param name="age"></param>
    ///<returns></returns>
    public int Update(int personID, string firstName, string lastName, int age)
    {
        
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand dCmd = new SqlCommand("UpdateData", conn);
        dCmd.CommandType = CommandType.StoredProcedure;
 
        try
        {
            dCmd.Parameters.AddWithValue("@FirstName", firstName);
            dCmd.Parameters.AddWithValue("@LastName", lastName);
            dCmd.Parameters.AddWithValue("@Age", age);
            dCmd.Parameters.AddWithValue("@PersonID", personID);
        }
        catch
        {
            throw;
        }
        finally
        {
            dCmd.Dispose();
            conn.Close();
            conn.Dispose();
        }
 
    }
 
    ///<summary>
    ///Load all records from database
    ///</Summary>
    ///<returns></returns>
 
    public DataTable Load()
    {
        
        SqlConnection conn = new SqlConnection(connStr);
        SqlDataAdapter dAd = new SqlDataAdapter("LoadAll", conn);
        dAd.SelectCommand.CommandType = CommandType.StoredProcedure;
        DataSet dSet = new DataSet();
        try
        {
            dAd.Fill(dSet, "PersonTable");
            return dSet.Tables["PersonTable"];
        }
 
        catch
        {
            throw;
        }
        finally
        {
            dSet.Dispose();
            dAd.Dispose();
            conn.Close();
            conn.Dispose();
        }
 
    }
 
    ///<summary>
    ///Delete records from database
    ///</summary>
    ///<param name="personID"></param>
    ///<returns></returns>
    ///
 
    public int Delete(int personID)
    {
        
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        SqlCommand dCmd = new SqlCommand("DeleteData", conn);
        dCmd.CommandType = CommandType.StoredProcedure;
 
 
        try
        {
            dCmd.Parameters.AddWithValue("@PersonID", personID);
            return dCmd.ExecuteNonQuery();
        }
        catch
        {
            throw;
 
        }
        finally
        {
            dCmd.Dispose();
            conn.Close();
            conn.Dispose();
        }
    }

Open in new window

0
Comment
Question by:Tapan Pattanaik
1 Comment
 
LVL 16

Accepted Solution

by:
burakiewicz earned 200 total points
ID: 23613616
change connStr to ConnStr
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question