Solved

Help with stored procedure command in class

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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