Subject: Re: ExecuteReader and output params
Date: Tue, 16 Sep 2003 08:16:51 -0400
Lines: 153
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.adonet
NNTP-Posting-Host: 108.newark-08rh15rt.nj.dial-access.att.net 12.89.174.108
Path: cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.adonet:61076
X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
I am not sure if we are talking about the same thing. I will try to break my
points and see where you agree and where not.
1. MS Data Access Block class SqlHelper has only static methods.
2. In this block Command object is always local variable so it is not
accessible for client of SqlHelper class
3. Because of 2. client of SqlHelper can't get Parameters collection after
DataReader is closed.
The problem is that I can't get output parameters from SqlHelper
So as the result I can't use this Block to access parameters after
DataReader is closed.
To create my owns solution I need to do something like this
(C#)
public class SqlHelper
{
SqlCommand cmd = new SqlCommand;
public SqlParameterCollection Parameters
{
get{return cmd.Parameters};
}
public SqlDataReader ExecuteReader (string conString, CommandType type,
string commandString, SqlParameter[] sqlParams)
{
SqlConnection con= new SqlConnection(conString);
cmd.CommandText= commandString;
cmd.CommandType=type;
cmd.Connection=con;
//fill the parameters
foreach(SqlParameter p in sqlParams)
{
//some checking probably should be done...
cmd.Parameters.Add(p);
}
con.Open();
SqlDataReader rd=cmd.ExecuteReader();
return rd;
}
}
Client uses this method to get SqlDataReader does with it whatever he wants,
closes it and retrieves parameters from Parameters property (or sqlParams)
William Ryan said:
Shimon:
No, I think you are missing the point. All you need to do is create and add
Paramters to add to the parameters collection. You can pass them in from
Anywhere, or you could add them in your calling code, and pass in the
command. I'm missing you about the All methods are static in the Framework.
The Paramters collection is not a static property, it's an instance one.
Show us your existing stuff and where you have the problem, there's
definitely a way to get there from here.
I'll be up for a while...so let me know.
Cheers,
Bill