Solved

problem with the following code

Posted on 2006-06-25
2
229 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
Comment Utility
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-
Comment Utility
Thank you AT,

That corrected the problem.  I appreciate your help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now