473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DAL - Accessing Output Parameters

Using an example in the Jan 2006 release of the Enterprise Library,
I came up with the code shown below to create a DAL method
for returning several columns of a single row. I place the output
parameter values in a comma-separated string, and then split
the string to get the individual values on the calling page. This
approach works, but I can't help but think there is a more
efficient way to accomplish this.

Thanks for any insight you can provide.

--------------------------------------------------
// DAL Method
public string WorkItemGet()
{
Database db = DatabaseFactory .CreateDatabase ();
string sqlCommand = "pr_WorkItems_G etByID";
DbCommand dbCommand = db.GetStoredPro cCommand(sqlCom mand);
// Add paramters
db.AddInParamet er(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParamet er(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParame ter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParame ter(dbCommand, "ProjectLeader" , DbType.String, 60);
db.AddOutParame ter(dbCommand, "WI_Description ", DbType.String, 200);

string wiString;

db.ExecuteNonQu ery(dbCommand);
// Row of data is captured via output parameters
wiString = string.Format(C ultureInfo.Curr entCulture, "{0}, {1}, {2}, {3}",
db.GetParameter Value(dbCommand , "WI_Title") ,
db.GetParameter Value(dbCommand , "ProjectLeader" ),
db.GetParameter Value(dbCommand , "WI_Description "));

return wistring
}

--------------------------------------------------
// Call
string WIGetResults = WI.WorkItemGet( );
string[] WIData = WIGetResults.Sp lit(',');
WI_Title.Text = WIData[0].ToString();
ProjectLeader.T ext = WIData[1].ToString();
WI_Description. Text = WIData[2].ToString();
Feb 25 '06 #1
1 8150

"Garth Wells" <no****@nowhere .com> wrote in message
news:e2******** ******@TK2MSFTN GP09.phx.gbl...
Using an example in the Jan 2006 release of the Enterprise Library,
I came up with the code shown below to create a DAL method
for returning several columns of a single row. I place the output
parameter values in a comma-separated string, and then split
the string to get the individual values on the calling page. This
approach works, but I can't help but think there is a more
efficient way to accomplish this.

Thanks for any insight you can provide.

--------------------------------------------------
// DAL Method
public string WorkItemGet()
{
Database db = DatabaseFactory .CreateDatabase ();
string sqlCommand = "pr_WorkItems_G etByID";
DbCommand dbCommand = db.GetStoredPro cCommand(sqlCom mand);
// Add paramters
db.AddInParamet er(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParamet er(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParame ter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParame ter(dbCommand, "ProjectLeader" , DbType.String, 60);
db.AddOutParame ter(dbCommand, "WI_Description ", DbType.String, 200);

string wiString;

db.ExecuteNonQu ery(dbCommand);
// Row of data is captured via output parameters
wiString = string.Format(C ultureInfo.Curr entCulture, "{0}, {1}, {2}, {3}",
db.GetParameter Value(dbCommand , "WI_Title") ,
db.GetParameter Value(dbCommand , "ProjectLeader" ),
db.GetParameter Value(dbCommand , "WI_Description "));

return wistring
}

--------------------------------------------------
// Call
string WIGetResults = WI.WorkItemGet( );
string[] WIData = WIGetResults.Sp lit(',');
WI_Title.Text = WIData[0].ToString();
ProjectLeader.T ext = WIData[1].ToString();
WI_Description. Text = WIData[2].ToString();


Stuffing the values into a string is completely unnecessary.

THis is better:

// DAL Method
public string[] WorkItemGet()
{
Database db = DatabaseFactory .CreateDatabase ();
string sqlCommand = "pr_WorkItems_G etByID";
DbCommand dbCommand = db.GetStoredPro cCommand(sqlCom mand);
// Add paramters
db.AddInParamet er(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParamet er(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParame ter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParame ter(dbCommand, "ProjectLeader" , DbType.String, 60);
db.AddOutParame ter(dbCommand, "WI_Description ", DbType.String, 200);

string wiString;

db.ExecuteNonQu ery(dbCommand);
// Row of data is captured via output parameters
return new string[] {
db.GetParameter Value(dbCommand , "WI_Title") ,
db.GetParameter Value(dbCommand , "ProjectLeader" ),
db.GetParameter Value(dbCommand , "WI_Description ") };

return wistring
}
string[] WIData = WI.WorkItemGet( );
WI_Title.Text = WIData[0].ToString();
ProjectLeader.T ext = WIData[1].ToString();
WI_Description. Text = WIData[2].ToString();


But this works well only because all of the parameters happen to be strings.
And you still have to remember the order in the calling code.

So this is better still:

public class WorkItem
{
string WI_Title;
string ProjectLeader;
string WI_Description;

public WorkItem(string WI_Title,
string ProjectLeader,
string WI_Description)
{
this.WI_Title = WI_Title;
this.ProjectLea der = ProjectLeader;
this.WI_Descrip tion = WI_Description;
)
}

// DAL Method
public string[] WorkItemGet()
{
Database db = DatabaseFactory .CreateDatabase ();
string sqlCommand = "pr_WorkItems_G etByID";
DbCommand dbCommand = db.GetStoredPro cCommand(sqlCom mand);
// Add paramters
db.AddInParamet er(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParamet er(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParame ter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParame ter(dbCommand, "ProjectLeader" , DbType.String, 60);
db.AddOutParame ter(dbCommand, "WI_Description ", DbType.String, 200);

string wiString;

db.ExecuteNonQu ery(dbCommand);
// Row of data is captured via output parameters
return new Workitem(
db.GetParameter Value(dbCommand , "WI_Title") ,
db.GetParameter Value(dbCommand , "ProjectLeader" ),
db.GetParameter Value(dbCommand , "WI_Description ") );
}
Workitem WIData = WI.WorkItemGet( );
WI_Title.Text = WIData.WI_Title ;
ProjectLeader.T ext = WIData.ProjectL eader;
WI_Description. Text = WIData.WI_Descr iption;


David
Feb 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3991
by: Bari Allen | last post by:
I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First varchar(80) OUTPUT , @Second varchar(80) OUTPUT , @Third varchar(80) OUTPUT , @Amount as numeric(18,0) OUTPUT etc.
4
1782
by: stjulian | last post by:
I have a stored procedure that is supposed to 1. Increment a counter in Table A via a transaction 2. Use this value as the primary key to add in an address to customers Table B (Referenced as a "DECLARE @CustomerID INT" just after the AS clause) 3. Return the primary key. This works perfectly when being called from Query Analyzer supplying values in an EXEC line, however, accessing it from .ASP (IIS 5.0 on Win2K), the
1
1872
by: Jay | last post by:
I hope this is the correct place to post this. I'm using a stored procedure to simply look up and return a value from a database. The db key is an integer, everything else is varchar. The stored proc is: CREATE procedure SP_IMAGE_NAME( @MAT_ID varchar(13), @TYPE varchar(1), @IMAGE_NM varchar(100) OUTPUT ) as
1
4553
by: Mullin Yu | last post by:
hi, i'm using System.Data.OracleClient; but it seems not having Varchar2 and i use Varchar instead. Then when i call a Oracle Procedure update a table with varchar2, i got the following error: ============== Error Message ==============
8
4457
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
2
2545
by: Bari Allen | last post by:
ASP Classic question: I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First varchar(80) OUTPUT , @Second varchar(80) OUTPUT , @Third varchar(80) OUTPUT , @Amount as numeric(18,0) OUTPUT
11
1531
by: Ryan Krauss | last post by:
I have a set of Python classes that represent elements in a structural model for vibration modeling (sort of like FEA). Some of the parameters of the model are initially unknown and I do some system identification to determine the parameters. After I determine these unknown parameters, I would like to substitute them back into the model and save the model as a new python class. To do this, I think each element needs to be able to read...
1
2010
by: Nestor | last post by:
Hello all, I'm begining in the web services world and I've reading about how to invoke them using javascript from Mozilla browser (version 2.0 in my case). I found a very interesting example here: http://www.mozilla.org/projects/webservices/examples/babelfish-wsdl/index.html The problem I have is this: When I try to adapt the invokation on the
2
3379
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables @idUser int OUTPUT,
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.