473,761 Members | 8,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlParameter ???

What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r
Nov 17 '05 #1
5 4605
Neither one. typeof(string) should be a SqlDbType (Char, VarChar, etc.)

This method works just fine if you want to use the defaults for your
parameter:

MyCommand.Param eters.Add("@par am1", SqlDbType.VarCh ar, 255).Value = "Hello";

For cases where I don't want defaults used (i.e., .Direction, etc.), I
prefer this method since it's a little cleaner:

SqlParameter myParam = new SqlParameter();
myParam.Size = 255;
myParam.Value = "Hello";
myParam.Directi on = ParameterDirect ion.Output;
MyCommand.Param eters.Add(myPar am);

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r

Nov 17 '05 #2
yes thanks, i know about the sqldbtype...tha nk u so much, but my main
question was about using or not SqlParameter class if u can access via
SqlCommand too...you think is SqlParameter as i saw, not ?

thnaks in advance

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r
"Michael C#" <ho***@boutdat. com> escreveu na mensagem
news:uC******** ******@TK2MSFTN GP09.phx.gbl...
Neither one. typeof(string) should be a SqlDbType (Char, VarChar, etc.)

This method works just fine if you want to use the defaults for your
parameter:

MyCommand.Param eters.Add("@par am1", SqlDbType.VarCh ar, 255).Value =
"Hello";

For cases where I don't want defaults used (i.e., .Direction, etc.), I
prefer this method since it's a little cleaner:

SqlParameter myParam = new SqlParameter();
myParam.Size = 255;
myParam.Value = "Hello";
myParam.Directi on = ParameterDirect ion.Output;
MyCommand.Param eters.Add(myPar am);

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r


Nov 17 '05 #3
Or even MyCommand.Param eters.Add("para m", typeof(string)) .Value="Hello
world";

Your two examples are functionally equivalent. Go with what suits your
typing style best.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r

Nov 17 '05 #4
BW
Either one will work. However that should be something like:
MyCommand.Param eters.Add("@par am1", SqlDbType.VarCh ar);

Not typeof(...); there is a difference

Anyway, your second example is handy if you want to pass an array of
SqlParameter.

HTH
B

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r

Nov 17 '05 #5
As I said, splitting it up makes it more readable if you want to set all the
properties of the SqlParameter individually. The other method is more
compact if you're not worried about setting all the properties.

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:e2******** ******@TK2MSFTN GP10.phx.gbl...
yes thanks, i know about the sqldbtype...tha nk u so much, but my main
question was about using or not SqlParameter class if u can access via
SqlCommand too...you think is SqlParameter as i saw, not ?

thnaks in advance

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r
"Michael C#" <ho***@boutdat. com> escreveu na mensagem
news:uC******** ******@TK2MSFTN GP09.phx.gbl...
Neither one. typeof(string) should be a SqlDbType (Char, VarChar, etc.)

This method works just fine if you want to use the defaults for your
parameter:

MyCommand.Param eters.Add("@par am1", SqlDbType.VarCh ar, 255).Value =
"Hello";

For cases where I don't want defaults used (i.e., .Direction, etc.), I
prefer this method since it's a little cleaner:

SqlParameter myParam = new SqlParameter();
myParam.Size = 255;
myParam.Value = "Hello";
myParam.Directi on = ParameterDirect ion.Output;
MyCommand.Param eters.Add(myPar am);

"Daniel Groh" <ne*********@gm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP12.phx.gbl...
What is the best way to access a procedure ?

MyCommand.Param eters.Add("@par am1",typeof(str ing));

or

SqlParameter myParam = new SqlParameter();
myParam.Add("@p aram1",typeof(s tring));

What do you think ?

--

Atenciosamente,

Daniel Groh
CTF Technologies do Brasil Ltda.
Analista Programador
Fone: 11 3837-4203
E-mail: dg***@ctf.com.b r



Nov 17 '05 #6

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

Similar topics

5
3136
by: Kenneth | last post by:
Can anyone explain me why it is neccesary to include SqlDbType to the SqlParameter. In every example I see, it is done, but no one explaines why. I have for example a date I want to save into my Sql Server database through a stored procedure-call. In the database it is defined as a SmallDateTime. Every 3 methods in the client-code below gives the same (and correct) result. So why is it that important? dim param As SqlParameter
1
7545
by: Marcin | last post by:
hi, I would like to ask how to serialize class with members like SqlParameter. I try to use BinaryFormatter. public class Example_Class { public SqlParameter sqlParam; public Example_Class()
2
3858
by: confused | last post by:
Hi, I want to assign a default value of DBNull.Value to my stored procedure parameter, but also have the ability to overwrite it, so: SqlParameter param = new SqlParameter ("@EmployeeId",SqlDbType.Char,10); param.Value = DBNull.Value; //but want to overwrite maybe
4
4340
by: Jason Huang | last post by:
Hi, I want to use the Sqlparameter and SqlDataAdapter to update my data, and the data will be updated based on two TextBoxes txtCustName and txtCustAddress. Thanks for help. Jason
5
8301
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is not working. The Address column is DataType NVarChar 90, no problem. Any idea?
0
2756
by: Elliot M. Rodriguez | last post by:
I implemented a very small, basic data access layer for my web application. It works just fine, except for this one bug. One of my methods returns an abstracted dataset. To accomodate X number of input parameters, I created a function signature that accepts a ParamArray of SqlParameters as well as the name of the stored proc. In the body of the function I loop through the param array and append each object to the Parameters collection of...
3
2765
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both my calling code and the webservice code are below. Thanks for your help. D:\Projects .NET\StoreBO\frmVoids.vb(182): Value of type '1-dimensional array of System.Data.SqlClient.SqlParameter' cannot be converted to '1-dimensional array of...
6
7844
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value) ' Can also be non-null, but sometimes is null param(0).Direction = ParameterDirection.InputOutput ' But, before we begin, store a copy of the existing parameters into another variable Dim param2() As SqlParameter = New SqlParameter(0) {}...
2
1685
by: tshad | last post by:
I am trying to build my own DB Class and am trying to set up my parameter list in an array of SqlParameter objects. In my regular code I would do something like: ********************************************************* Dim dbCmd As SqlCommand = New SqlCommand("GetUsers", dbConn) dbCmd.CommandType = CommandType.StoredProcedure dbCmd.Parameters.Add("@UserID",SqlDBType.Int).value = 1...
0
9531
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
10115
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, 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...
1
9905
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
9775
tracyyun
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...
1
7332
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...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
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...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2752
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.