Solved

Help with stored procedure command in class

Posted on 2006-07-16
3
189 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

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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!
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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