0

Currently I'm using SqlHelper.ExecuteDataSet(string storedProcedure, Object[] parameters); to retrieve data from the database. The issue resides in the fact that order matters. I recently abstracted some of the functionality that produces the Object[] parameters which caused them to get out of order a bit. I was wondering if there was a way to call this function (simplistically) my specifying the names?

The only other solution I could come up with is make a function myself to order them properly, though this seems subpar to an already existing way of doing it.

Question: Is there a way to call SqlHelper.ExecuteDataSet with a set of named parameters? (Such as with a Dictionary<String, Object> or something of the sort)?

Shelby115
  • 2,816
  • 3
  • 36
  • 52
  • Ummm `Microsoft.ApplicationBlocks.Data.SqlHelper` Sorry didn't realize. – Shelby115 Nov 18 '14 at 16:25
  • I can't find much documentation by searching. A quick google reveals [this page](ftp://63.240.151.59/Inetpub/agcdirect/CodeCommentReport/Microsoft.ApplicationBlocks.Data/CWP24.HTM) which seems to infer there is an overload that takes an array of [SqlParameters](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter%28v=vs.110%29.aspx) which can be named etc. – Bridge Nov 18 '14 at 16:40

2 Answers2

0

SqlHelper is obsolete. It was replaced by the Database object from MS Enterprise Library, but this is also obsolete. What functionality are you trying to extrude from it? You might be better off building your own abstraction layer using the Enterprise Library as a starting point.

Elliot Rodriguez
  • 608
  • 6
  • 25
  • We're using it to run queries. It works just fine but parameters are out of order. I guess I'll have to make a function to order the parameters myself then? (For the procedures I can't modify to order that is). – Shelby115 Nov 18 '14 at 16:51
  • Yes. I am curious to see what modifications you made that cause it to go out of order. – Elliot Rodriguez Nov 18 '14 at 16:55
  • Simple Abstraction. I didn't realize some had the order `P1 P2 P3 P4 P5` and others had the order `P1 P5 P2 P3 P4`. I was able to correct most instances in the StoredProcedures themselves but there are a couple I'm not allowed to touch. – Shelby115 Nov 18 '14 at 16:59
  • What if you queried against the stored procedure prior to execution? Assuming you have access to the SYS schema, you can try matching parameter order then: http://stackoverflow.com/questions/7366912/find-the-parameter-names-of-a-stored-procedure – Elliot Rodriguez Nov 18 '14 at 17:04
0

go to these links you will find your answer. We can handle dictionary and other types:

http://www.codeproject.com/Articles/63147/Handling-database-connections-more-easily

http://geansoft.googlecode.com/svn/trunk/Gean/Gean.Data/ORM/DAL/Helper/MsSqlHelper.cs

Rahul Sharma
  • 453
  • 3
  • 10