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

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

LVL 22
Tapan PattanaikSenior EngineerAsked:
Who is Participating?
 
burakiewiczCommented:
change connStr to ConnStr
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.