We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

Medium Priority
286 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

Comment
Watch Question

change connStr to ConnStr

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.