Solved

Help with stored procedure command in class

Posted on 2006-07-16
3
186 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
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

856 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