Solved

Help with stored procedure command in class

Posted on 2006-07-16
3
187 Views
Last Modified: 2010-04-16
I'm having syntax trouble below when I tried to add a stord procedure command and I'm not sure how to fix the syntax here:

    public class GetListURLs
    {

       private string _ConnString;

        public GetListURLs(string connection)
        {
            this._ConnString = connection;
        }

        public DataSet GetList()
        {
            DataSet URLs = new DataSet();
            SqlConnection Conn = new SqlConnection(this._ConnString);
            try
            {

                SqlCommand GetURLsCommand = new SqlCommand("GetURLs", Conn);
                GetURLsCommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(GetURLsCommand, Conn);
                da.Fill(URLs);
                return URLs;
            }
            catch
            {
                return null;
            }

        }
    }
0
Comment
Question by:dba123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
whatsit2002 earned 500 total points
ID: 17118022
Hi dba123,

Try this:

                SqlDataAdapter da = new SqlDataAdapter(GetURLsCommand);

You don't need to pass the connection in to your data adapter since you have already created the command with it.

Jason
0
 
LVL 1

Author Comment

by:dba123
ID: 17118187
cool, thanks, it worked.  I wouldn't have known that...errr.

Also, besides my Conn, what else should I close in my Finally?
0
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17118210
I don't see anything else that your finally needs to take care of. The connection should be good enough.

Thanks.

Jason
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# LINQ ForEach() question 6 78
abstract class C# 1 36
Exception when using Alea null reference in fsharp.core.dll 3 52
Connect Gridview column to Textbox in C# 2 36
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

761 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