How to pass store procedure info to other routine RRS feed

  • Question

  • i like to know how could i develop a class which will have store proc name and as well as parameter info like

    param name and value with type. after populate store proc info then i like to pass that data to other routine which will execute that store proc with param data and return result.

    design is not coming to my mind. anyone could help.

    i read a write from here but does look very good

    • Moved by CoolDadTx Tuesday, September 8, 2015 3:43 PM ADO related
    Tuesday, September 8, 2015 3:12 PM


All replies

  • That is sort of the purpose of a DbCommand.  It encapsulates the command and parameters.  Pass the command to whatever code you want. If you want something a little more generic then you can read my blog post on how we do it where I work.

    Alternatively you can consider using an ORM which reduces the need for sprocs and allows for you to work with regular objects. Yet another option is to use an interface that encapsulates the actual sproc call with a simple method that code can call instead.

    Michael Taylor

    Tuesday, September 8, 2015 3:42 PM
  • What you are talking about doesn't make any sense. What is the purpose of having one class or function implement the sproc usage  and pass it to another class or function?

    It makes no sense, and the usage of the sproc has to happen in the class that is working with it and executed in the class or function that is setting the sproc up to be used.

    However, there is nothing stopping you from using a List<T> with a custom object, using a datareader, creating custom objects from the returned results, loading them into a List<T> and passing the List<T> to another class and methods in the class or to methods in the same class that executed the sproc in one of its methods. 

    Tuesday, September 8, 2015 3:47 PM
  • You might want to take a look at my 3-part series on Data Access for some basic ideas:

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post has a more complete example class, but it gets into using anonymous delegates and may be too much for a beginner (which, to be honest, I don't use the anonymous delegates anymore, but I used to on previous projects several years ago). However, even if you don't want to use the anonymous delegate approach, the more complete example class should show you how to save data, which the examples in the first two posts don't do.

    Those 3 posts are old, I wrote them back in 2009. They are still relevant, but I needed to add two things: implementing IDisposable and using TransactionScope for transactions. So, here's the latest post in my Data Access series:

    Several of my readers have gotten back to me with some questions about the code from all four posts and I realize that I'm still missing a few important items, such as DataAdapter.TableMappings!! So, I still have a few additions for this blog series, but I haven't been able to get to it yet. It's on my to-do list, though!  ;)

    ~~Bonnie DeWitt [C# MVP]

    Wednesday, September 9, 2015 5:02 AM