Solved

problem with the following code

Posted on 2006-06-25
2
239 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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