Solved

problem with the following code

Posted on 2006-06-25
2
238 Views
Last Modified: 2010-04-16
I created the following class file:

public class DataAccess
      {
            public DataAccess()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }
            public static SqlDataReader GetDepartments()
            {
                  SqlConnection connection = new SqlConnection(connectionString);
                  SqlCommand command = new SqlCommand("GetTopNav", connection);
                  command.CommandType = CommandType.StoredProcedure;
                  connection.Open();
                  return command.ExecuteReader(CommandBehavior.CloseConnection);
            }
            private static string connectionString
            {
                  get
                  {
                        return ConfigurationSettings.AppSettings("ConnectionString");
                  }
            }
      }
}

I'm getting error on the following lines:

command.CommandType = CommandType.StoredProcedure;

return command.ExecuteReader(CommandBehavior.CloseConnection);

return ConfigurationSettings.AppSettings("ConnectionString");  //this references the connection string stored in the web.config file

Thanks for any help.
0
Comment
Question by:-Dman100-
2 Comments
 
LVL 10

Accepted Solution

by:
athapa earned 500 total points
ID: 16980690
Add this to the top of the page.

using System.Data;
using System.Configuration;

These should be already there but if not make sure these are on the top too.
using System;
using System.Data.SqlClient;

Change this
  return ConfigurationSettings.AppSettings("ConnectionString");
to
   return ConfigurationSettings.AppSettings["ConnectionString"];

AT
0
 

Author Comment

by:-Dman100-
ID: 16980711
Thank you AT,

That corrected the problem.  I appreciate your help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to reference objects of the calling class without passing them as parameters 29 206
Hey!!!! 1 24
C# winforms programmitically move panels 6 43
defining NULL or 0 10 44
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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