473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_GetByID";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
// Add paramters
db.AddInParameter(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParameter(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParameter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParameter(dbCommand, "ProjectLeader", DbType.String, 60);
db.AddOutParameter(dbCommand, "WI_Description", DbType.String, 200);

string wiString;

db.ExecuteNonQuery(dbCommand);
// Row of data is captured via output parameters
wiString = string.Format(CultureInfo.CurrentCulture, "{0}, {1}, {2}, {3}",
db.GetParameterValue(dbCommand, "WI_Title"),
db.GetParameterValue(dbCommand, "ProjectLeader"),
db.GetParameterValue(dbCommand, "WI_Description"));

return wistring
}

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

"Garth Wells" <no****@nowhere.com> wrote in message
news:e2**************@TK2MSFTNGP09.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_GetByID";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
// Add paramters
db.AddInParameter(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParameter(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParameter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParameter(dbCommand, "ProjectLeader", DbType.String, 60);
db.AddOutParameter(dbCommand, "WI_Description", DbType.String, 200);

string wiString;

db.ExecuteNonQuery(dbCommand);
// Row of data is captured via output parameters
wiString = string.Format(CultureInfo.CurrentCulture, "{0}, {1}, {2}, {3}",
db.GetParameterValue(dbCommand, "WI_Title"),
db.GetParameterValue(dbCommand, "ProjectLeader"),
db.GetParameterValue(dbCommand, "WI_Description"));

return wistring
}

--------------------------------------------------
// Call
string WIGetResults = WI.WorkItemGet();
string[] WIData = WIGetResults.Split(',');
WI_Title.Text = WIData[0].ToString();
ProjectLeader.Text = 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_GetByID";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
// Add paramters
db.AddInParameter(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParameter(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParameter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParameter(dbCommand, "ProjectLeader", DbType.String, 60);
db.AddOutParameter(dbCommand, "WI_Description", DbType.String, 200);

string wiString;

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

return wistring
}
string[] WIData = WI.WorkItemGet();
WI_Title.Text = WIData[0].ToString();
ProjectLeader.Text = 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.ProjectLeader = ProjectLeader;
this.WI_Description = WI_Description;
)
}

// DAL Method
public string[] WorkItemGet()
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "pr_WorkItems_GetByID";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
// Add paramters
db.AddInParameter(dbCommand, "WI_ID", DbType.Int32, wi_id);
db.AddInParameter(dbCommand, "WI_Type", DbType.String, "project");
// Output parameters
db.AddOutParameter(dbCommand, "WI_Title", DbType.String, 100);
db.AddOutParameter(dbCommand, "ProjectLeader", DbType.String, 60);
db.AddOutParameter(dbCommand, "WI_Description", DbType.String, 200);

string wiString;

db.ExecuteNonQuery(dbCommand);
// Row of data is captured via output parameters
return new Workitem(
db.GetParameterValue(dbCommand, "WI_Title"),
db.GetParameterValue(dbCommand, "ProjectLeader"),
db.GetParameterValue(dbCommand, "WI_Description") );
}
Workitem WIData = WI.WorkItemGet();
WI_Title.Text = WIData.WI_Title;
ProjectLeader.Text = WIData.ProjectLeader;
WI_Description.Text = WIData.WI_Description;


David
Feb 25 '06 #2

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

Similar topics

1
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 ,...
4
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...
1
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...
1
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: ...
8
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
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...
11
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...
1
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...
2
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 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.