Re: Creating A Custom Collection

From: Matt Berther (mberther_at_hotmail.com)
Date: 09/17/04


Date: Fri, 17 Sep 2004 12:16:49 -0700

Hello Kapil,

I have an introduction to implementing CollectionBase to create a strongly typed collection available on my website:

http://www.mattberther.com/2004/09/000540.html

You'll have to get away from using multidimensional arrays. I see an object in what you describe.

public class Parameter
{
    public string Name;
    public SqlDbType DataType;
    public object Value;
}

I'm using fields as an example, you would probably go through and implement these as properties. From here, you'd create your CollectionBase derived implementation to work with this Parameter class.

You're resulting code would look something like this:

ParameterCollection coll = new ParameterCollection();
coll.Add(new Parameter("name", SqlDbType.Int, "value"));

Hope this helps...

--
Matt Berther
http://www.mattberther.com
> Hi,
> 
> I have an idea but I need some help. Basically I want to create an
> object  that is used to communicate between the front end of my
> application and the  database. This object will be used by my data
> layer to execute stored  procedures on the database. It will receve
> such parameters such as:
> 
> string StoredProcedureName, string UserName, string TransactionType
> and one  more which would be a collection of some sort. I would send
> this object to  send it an object that holds the parameters for the
> stored procedure so it  can walk this object to create a SqlCommand
> object and execute the stored  procedure.
> 
> The problem is that how do I create a multi demencial array where the
> first  column has a type of string and is called ParameterName, the
> 2nd column has a  type of System.Data.SqlClient.SqlDbType and be
> called ParameterDataType, and  the 3rd should be of type varient or
> object since and be called  ParameterValue.
> 
> The point of all this is to allow the business layer of the app to
> send the  name of the proc and the parameters object to the data layer
> and the data  layer can walk the parameter object and convert it to an
> SqlCommnad and  execute a stored procedure.
> 
> I think creating a custom collection may help but I have never used a
> collection and it seems that I can only have one dimension in a
> collection or  a name value pair.
> 
> Any ideas?
> 
> Thanks
> KP


Relevant Pages

  • Re: Creating A Custom Collection
    ... Now I created a method in my data layer called create ... SQlCommand that will receve the Parameters Collection as a parameter, ... >> string StoredProcedureName, string UserName, string TransactionType ... >> stored procedure so it can walk this object to create a SqlCommand ...
    (microsoft.public.dotnet.framework)
  • Creating A Custom Collection
    ... This object will be used by my data layer to execute stored ... string StoredProcedureName, string UserName, string TransactionType and one ... send it an object that holds the parameters for the stored procedure so it ...
    (microsoft.public.dotnet.framework)
  • RE: SQL stored procedure executing twice
    ... from one parent record to another. ... Dim stDocName As String ... My pass-thru query syntax going to stored procedure ...
    (microsoft.public.access.modulesdaovba)
  • RE: MS Query "Connections"
    ... handle that with my connection string. ... for using the stored procedure route is that it is faster. ... If you truly want to pass in the query string, ...
    (microsoft.public.excel.programming)
  • Re: XML binding advice
    ... Performance - By writing the SQL statement as a stored procedure, ... execution plan will take into account any indexes you have on the tables ... each piece you add to the string. ...
    (microsoft.public.dotnet.xml)