• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Help with stored procedure command in class

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
dba123
Asked:
dba123
  • 2
1 Solution
 
whatsit2002Commented:
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
 
dba123Author Commented:
cool, thanks, it worked.  I wouldn't have known that...errr.

Also, besides my Conn, what else should I close in my Finally?
0
 
whatsit2002Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now