By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,216 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,216 IT Pros & Developers. It's quick & easy.

Using MS Data Access application block to call stored procedure with parameters

P: n/a
JM
Hi,

I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored
procedure using Latest Enterprise Library 2.0. My stored procedure has
3 input parameters: CustId (int), RefId(int) and EmailId(varchar 200)
and it returns a dataset.

This is how I am trying to do:
-------------
int CustId = 1
int RefId = 1
string EmailId = "so******@email.com"

Database db = DatabaseFactory.CreateDatabase("ConnectionString") ;
//Need help in following line
DataSet ds = db.ExecuteDataSet("get_CustData", params object[]
parameterValues);
-------------------

Can anybody tell me how I can create this params object with the
values of all 3 parameters. And whats the best way to use enterprise
library for SQL Server database.

Thanks
JM

Feb 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

You have to get hold of the instance of hte new 2.0 Abstract class
DbCommand
public DataSet GetOrdersByCustomerID(string customerID)
{
Database northwind = DatabaseFactory.CreateDatabase();

DbCommand command = northwind.GetSqlStringCommand ("SELECT
[OrderID],[OrderDate] FROM [Orders] WHERE [CustomerID] =
@CustomerID"); //OR DbCommand command =
northwind.GetStoredProcedure("dbo.uspGetAllOrders" )
northwind.AddInParameter(command, "@CustomerID",
DbType.String, customerID);
DataSet orders = new DataSet();

northwind.LoadDataSet(command, orders, "orders");

return orders;
}

I prefer the LoadDataSet over the ExecuteDataSet method.

You can find more examples by going here:

http://www.google.com/search?hl=en&q...InParameter%22

which is where I pulled the example from


"JM" <jm******@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Hi,

I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored
procedure using Latest Enterprise Library 2.0. My stored procedure has
3 input parameters: CustId (int), RefId(int) and EmailId(varchar 200)
and it returns a dataset.

This is how I am trying to do:
-------------
int CustId = 1
int RefId = 1
string EmailId = "so******@email.com"

Database db = DatabaseFactory.CreateDatabase("ConnectionString") ;
//Need help in following line
DataSet ds = db.ExecuteDataSet("get_CustData", params object[]
parameterValues);
-------------------

Can anybody tell me how I can create this params object with the
values of all 3 parameters. And whats the best way to use enterprise
library for SQL Server database.

Thanks
JM

Feb 13 '07 #2

P: n/a
JM
Hi,

Thanks for the prompt reply. I am able to use sp using DBCommand
object.

Thanks
JM

On Feb 13, 11:23 am, "sloan" <s...@ipass.netwrote:
You have to get hold of the instance of hte new 2.0 Abstract class
DbCommand

public DataSet GetOrdersByCustomerID(string customerID)
{
Database northwind = DatabaseFactory.CreateDatabase();

DbCommand command = northwind.GetSqlStringCommand ("SELECT
[OrderID],[OrderDate] FROM [Orders] WHERE [CustomerID] =
@CustomerID"); //OR DbCommand command =
northwind.GetStoredProcedure("dbo.uspGetAllOrders" )
northwind.AddInParameter(command, "@CustomerID",
DbType.String, customerID);
DataSet orders = new DataSet();

northwind.LoadDataSet(command, orders, "orders");

return orders;

}

I prefer the LoadDataSet over the ExecuteDataSet method.

You can find more examples by going here:

http://www.google.com/search?hl=en&q...ommand+%22AddI...

which is where I pulled the example from

"JM" <jmcha...@gmail.comwrote in message

news:11**********************@v33g2000cwv.googlegr oups.com...
Hi,
I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored
procedure using Latest Enterprise Library 2.0. My stored procedure has
3 input parameters: CustId (int), RefId(int) and EmailId(varchar 200)
and it returns a dataset.
This is how I am trying to do:
-------------
int CustId = 1
int RefId = 1
string EmailId = "someb...@email.com"
Database db = DatabaseFactory.CreateDatabase("ConnectionString") ;
//Need help in following line
DataSet ds = db.ExecuteDataSet("get_CustData", params object[]
parameterValues);
-------------------
Can anybody tell me how I can create this params object with the
values of all 3 parameters. And whats the best way to use enterprise
library for SQL Server database.
Thanks
JM- Hide quoted text -

- Show quoted text -

Feb 13 '07 #3

P: n/a
For informational purposes, the params object[] array of parameter values can
be constructed like this:

object[] myParams = { "Abc", 23, DateTime.Now, "etc."};

Pass "myParams" in the last position of the method signature.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"JM" wrote:
Hi,

I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored
procedure using Latest Enterprise Library 2.0. My stored procedure has
3 input parameters: CustId (int), RefId(int) and EmailId(varchar 200)
and it returns a dataset.

This is how I am trying to do:
-------------
int CustId = 1
int RefId = 1
string EmailId = "so******@email.com"

Database db = DatabaseFactory.CreateDatabase("ConnectionString") ;
//Need help in following line
DataSet ds = db.ExecuteDataSet("get_CustData", params object[]
parameterValues);
-------------------

Can anybody tell me how I can create this params object with the
values of all 3 parameters. And whats the best way to use enterprise
library for SQL Server database.

Thanks
JM

Feb 13 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.