Hi...
I have a stored procedure that takes in a large number of parameters (around
30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code
as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for
large numbers of parameters?
Thanks!
Alex 6 2567
Take a look at the Data Access block, included with the Enterprise Library. http://www.gotdotnet.com/codegallery...2-91be63527327
Depending on the version (1.x or 2.x), it will vary, but the concept remains
the same
It reduces database calls to this pseudo code
Database db = Database.Create Factory("");
DBCommand cmd = db.GetStoredPro cCommandWrapper ("StoredProcNam e");
cmd.AddInParame ter("InboundPar am1", DbType.String, ParamValue);
cmd.AddOutParam eter("OutParam1 ", DbType.Int32, 4);
cmd.AddOutParam eter("OutParam2 ", DbType.Int32, 4);
db.ExecuteNonQu ery(cmd);
cmd.GetParamete rValue("OutPara m1"); //get value of outbound param
cmd.GetParamete rValue("OutPara m2"); //get value of outbound param
2 things I really like about it is
1. No need for @; the prefix is defined by the DB type in the setup
2. In theory, you can change the connection string to another DB type with
no changes to the data tier.
HTH,
Morgan
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. . Hi...
I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter(); prmCustAcctID.P arameterName = "@CustAcctI D"; prmCustAcctID.S qlDbType = SqlDbType.NVarC har; prmCustAcctID.D irection = ParameterDirect ion.Input; prmCustAcctID.S ize = 30; prmCustAcctID.V alue = strCustAcctID; cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for large numbers of parameters?
Thanks! Alex
And to answer you question about performance... the # of parameters should
be a non-issue. The params are passed all at once when the command action is
called. I would be more concerned about what the proc's are doing once they
get the params.
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. . Hi...
I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter(); prmCustAcctID.P arameterName = "@CustAcctI D"; prmCustAcctID.S qlDbType = SqlDbType.NVarC har; prmCustAcctID.D irection = ParameterDirect ion.Input; prmCustAcctID.S ize = 30; prmCustAcctID.V alue = strCustAcctID; cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for large numbers of parameters?
Thanks! Alex
Morgan,
Thanks for your quick response. The stored procedure itself is quite fast -
it just performs some validation on the parameters then uses them to insert
rows into a number of tables - this is much faster than calling multiple
inserts directly from C#, as some parameters are used more than once in the
various inserts (already did some performance testing on that which is why I
ended up with this scenario).
My main concern was finding the fastest way of building and passing the
parameters from C# to SQL... I'll have a look at the Data Access Block too,
thanks.
Regards,
Alexis
First of all, because ParameterDirect ion.Input is the default, for all your
inpur parameters you can reduce the number of lines of code by using:
cmd.Parameters. Add("@CustAcctI D", SqlDbType.NVarC har, 30).Value =
strCustAcctID;
Before you get hung up on a 'very long block of code!!!', have you
determined how long it takes to execute the resulting block of code. I think
you might be surprised at how little time it actually takes and that your
'problem' is a non-event.
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. . Hi...
I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter(); prmCustAcctID.P arameterName = "@CustAcctI D"; prmCustAcctID.S qlDbType = SqlDbType.NVarC har; prmCustAcctID.D irection = ParameterDirect ion.Input; prmCustAcctID.S ize = 30; prmCustAcctID.V alue = strCustAcctID; cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for large numbers of parameters?
Thanks! Alex
If you don't want to handle parameter declaration code why not try
Microsoft Data Access Block.
Stephany Young wrote: First of all, because ParameterDirect ion.Input is the default, for all your inpur parameters you can reduce the number of lines of code by using:
cmd.Parameters. Add("@CustAcctI D", SqlDbType.NVarC har, 30).Value = strCustAcctID;
Before you get hung up on a 'very long block of code!!!', have you determined how long it takes to execute the resulting block of code. I think you might be surprised at how little time it actually takes and that your 'problem' is a non-event.
"Alex" <no****@hotmail .com> wrote in message news:43******** *************@n ews.zen.co.uk.. .
Hi...
I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter(); prmCustAcctID.P arameterName = "@CustAcctI D"; prmCustAcctID.S qlDbType = SqlDbType.NVarC har; prmCustAcctID.D irection = ParameterDirect ion.Input; prmCustAcctID.S ize = 30; prmCustAcctID.V alue = strCustAcctID; cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for large numbers of parameters?
Thanks! Alex
You may want to look at the SqlCommandBuild er class. This will allow
you to populate the parameters from the sql stored procedure. It will
cause actual execution time to be slower (cause it has to round-trip the
server to get the information) (although probably not noticably) but
will reduce the amount of code you have to write.
John
Alex wrote: Hi...
I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code as follows:
SqlParameter prmCustAcctID = cmd.CreateParam eter(); prmCustAcctID.P arameterName = "@CustAcctI D"; prmCustAcctID.S qlDbType = SqlDbType.NVarC har; prmCustAcctID.D irection = ParameterDirect ion.Input; prmCustAcctID.S ize = 30; prmCustAcctID.V alue = strCustAcctID; cmd.Parameters. Add(prmCustAcct ID);
Multiply this by around 40, and you get a very long block of code!!!
Is there a better/faster/more improved way of doing something like this for large numbers of parameters?
Thanks! Alex
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jarrod Morrison |
last post by:
Hi All
Im generally a vb programmer and am used to referencing multiple records
returned from a query performed on an sql database and im trying to move
some functions of my software into sql stored procedures. So far ive been
able to move the functions relatively easily but im unsure about how to
output multiple values from an sql stored procedure. By this i mean for
example one of the stored procedures may take your username and return...
|
by: Nashat Wanly |
last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and
Visual C# .NET
View products that this article applies to.
This article was previously published under Q310070
For a Microsoft Visual Basic .NET version of this article, see 308049.
For a Microsoft Visual C++ .NET version of this article, see 310071.
For a Microsoft Visual J# .NET version of this article, see 320627.
This article refers to the following Microsoft .NET...
|
by: Rhino |
last post by:
I am trying to get a sense of requirements and best practices for Java
stored procedures in DB2 V7.2 for Windows.
1. Is it required or recommended that any of the following be closed before
leaving the stored procedure: open Statement and PreparedStatement objects;
open ResultSet objects; open JDBC connections? Although the stored procedure
will still run succesfully if these open objects and connections are not
closed, are there any...
|
by: Dino L. |
last post by:
How can I run stored procedure (MSSQL) ?
|
by: Woody Splawn |
last post by:
I am using SQL Server 2000 as the back-end. I have created a stored
procedure in SQL server called usp_AddContract. This Stored procedure
inserts a new contract into a contracts table. I have tested the code in
Enterprise Manager and it works correctly. At the time that I run the SP I
pass a contract number and a SSN to the SP and it creates a new contract in
the contracts table with a unique value in the ConNum field and SSN field.
In...
| |
by: John |
last post by:
Hi
When developing vb.bet winform apps bound to sql server datasource, is it
preferable to use SELECTs or stored procedure to read and write data from/to
SQL Server? Why?
Thanks
Regards
|
by: Alex |
last post by:
Hi...
I have a stored procedure that takes in a large number of parameters (around
30) and returns (as output parameters) another 10 or so.
At the moment, each parameter is declared, defined and added in my C# code
as follows:
SqlParameter prmCustAcctID = cmd.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
|
by: E11esar |
last post by:
Hello there.
I am going in bit of a circle with this matter;
First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line at a time into an array, using a
string columns = line.Split(separators.ToCharArray());
command.
Here is a definition of the table I am loading into:
|
by: Soniad |
last post by:
Hello,
I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable (confirmation) declared in page.
Dim RsSp , SQLSp
Set RsSp = Server.CreateObject("ADODB.Recordset")
SQLSp = "Declare @confirm varchar(1)"
SQLSp = SQLSp & "Exec SendMsg_proc "& "'" & UniCode &"' , '" & DintUserId &"' , '" & DintOrg_id &"' ,...
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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
| |