Solved

problem with the following code

Posted on 2006-06-25
2
237 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

815 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

13 Experts available now in Live!

Get 1:1 Help Now