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

Shortest code footprint for .Parameter.Add?

P: n/a
Is there a way to replace the commented out parameter add syntax with a
single line of code, like the .Parameter.Add("@Letter"...) line below (which
does not work)?

'Dim prmLetter As New SqlParameter

'With prmLetter

' .ParameterName = "@Letter"

' .SqlDbType = SqlDbType.Char

' .Direction = ParameterDirection.Input

' .Value = chrLetter

'End With

With cmd

.CommandType = CommandType.StoredProcedure

.CommandText = "GetMasterIndexRowsWithLetter"

.Parameters.Add("@Letter", SqlDbType.Char, 1, chrLetter)

'.Parameters.Add(prmLetter)

End With

Thanks,

Dean Slindee
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Dean,

You can use the following overload to create the parameter to add the
parameter to the SqlCommand.

SqlParameter p = SqlCommand.Parameters.Add(new SqlParameter(String,
SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String,
DataRowVersion, Object));

p.Value = chrLetter;

However, the value has to be set sepeartely.

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Dean Slindee" <sl*****@mindspring.com>
| Subject: Shortest code footprint for .Parameter.Add?
| Date: Thu, 13 Nov 2003 12:42:59 -0600
| Lines: 39
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <uZ**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 0-1pool36-7.nas14.milwaukee1.wi.us.da.qwest.net
63.156.36.7
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156600
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Is there a way to replace the commented out parameter add syntax with a
| single line of code, like the .Parameter.Add("@Letter"...) line below
(which
| does not work)?
|
| 'Dim prmLetter As New SqlParameter
|
| 'With prmLetter
|
| ' .ParameterName = "@Letter"
|
| ' .SqlDbType = SqlDbType.Char
|
| ' .Direction = ParameterDirection.Input
|
| ' .Value = chrLetter
|
| 'End With
|
|
|
| With cmd
|
| .CommandType = CommandType.StoredProcedure
|
| .CommandText = "GetMasterIndexRowsWithLetter"
|
| .Parameters.Add("@Letter", SqlDbType.Char, 1, chrLetter)
|
| '.Parameters.Add(prmLetter)
|
| End With
|
|
|
| Thanks,
|
| Dean Slindee
|
|
|

Nov 20 '05 #2

P: n/a
For more information, please refer to the following link:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemDataSqlClientSqlParameterClassctorTopic 6.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Newsgroups: microsoft.public.dotnet.languages.vb
| From: v-****@online.microsoft.com (Kevin Yu [MSFT])
| Organization: Microsoft
| Date: Fri, 14 Nov 2003 06:33:30 GMT
| Subject: RE: Shortest code footprint for .Parameter.Add?
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
|
| Hi Dean,
|
| You can use the following overload to create the parameter to add the
| parameter to the SqlCommand.
|
| SqlParameter p = SqlCommand.Parameters.Add(new SqlParameter(String,
| SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String,
| DataRowVersion, Object));
|
| p.Value = chrLetter;
|
| However, the value has to be set sepeartely.
|
| HTH. If anything is unclear, please feel free to reply to the post.
|
| Kevin Yu
| =======
| "This posting is provided "AS IS" with no warranties, and confers no
| rights."
|
| --------------------
| | From: "Dean Slindee" <sl*****@mindspring.com>
| | Subject: Shortest code footprint for .Parameter.Add?
| | Date: Thu, 13 Nov 2003 12:42:59 -0600
| | Lines: 39
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Message-ID: <uZ**************@TK2MSFTNGP10.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.languages.vb
| | NNTP-Posting-Host: 0-1pool36-7.nas14.milwaukee1.wi.us.da.qwest.net
| 63.156.36.7
| | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156600
| | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| |
| | Is there a way to replace the commented out parameter add syntax with a
| | single line of code, like the .Parameter.Add("@Letter"...) line below
| (which
| | does not work)?
| |
| | 'Dim prmLetter As New SqlParameter
| |
| | 'With prmLetter
| |
| | ' .ParameterName = "@Letter"
| |
| | ' .SqlDbType = SqlDbType.Char
| |
| | ' .Direction = ParameterDirection.Input
| |
| | ' .Value = chrLetter
| |
| | 'End With
| |
| |
| |
| | With cmd
| |
| | .CommandType = CommandType.StoredProcedure
| |
| | .CommandText = "GetMasterIndexRowsWithLetter"
| |
| | .Parameters.Add("@Letter", SqlDbType.Char, 1,
chrLetter)
| |
| | '.Parameters.Add(prmLetter)
| |
| | End With
| |
| |
| |
| | Thanks,
| |
| | Dean Slindee
| |
| |
| |
|

Nov 20 '05 #3

P: n/a
Thank you, that's what I needed.
Actually, you can enter the value on the same line too as shown below (works
for the one parm I tested below): I would rather the commented out line
worked, syntax is accepted, but get an error message (shown) when executing.
Nevertheless, glad to have one example that does work.
With cmd

.CommandType = CommandType.StoredProcedure

.CommandText = "GetMasterIndexRowsWithLetter"

'.Parameters.Add(New SqlParameter("@Letter",
SqlDbType.Char, 1, chrLetter)) 'Error returned: @Letter not supplied

.Parameters.Add(New SqlParameter("@Letter",
SqlDbType.Char, 1, ParameterDirection.Input, False, 0, 0, "",
DataRowVersion.Current, chrLetter))

End With

Dean Slindee

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:gE**************@cpmsftngxa06.phx.gbl...
For more information, please refer to the following link:

http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfSystemDataSqlClientSqlParameterClassctorTopic 6.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| Newsgroups: microsoft.public.dotnet.languages.vb
| From: v-****@online.microsoft.com (Kevin Yu [MSFT])
| Organization: Microsoft
| Date: Fri, 14 Nov 2003 06:33:30 GMT
| Subject: RE: Shortest code footprint for .Parameter.Add?
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
|
| Hi Dean,
|
| You can use the following overload to create the parameter to add the
| parameter to the SqlCommand.
|
| SqlParameter p = SqlCommand.Parameters.Add(new SqlParameter(String,
| SqlDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String,
| DataRowVersion, Object));
|
| p.Value = chrLetter;
|
| However, the value has to be set sepeartely.
|
| HTH. If anything is unclear, please feel free to reply to the post.
|
| Kevin Yu
| =======
| "This posting is provided "AS IS" with no warranties, and confers no
| rights."
|
| --------------------
| | From: "Dean Slindee" <sl*****@mindspring.com>
| | Subject: Shortest code footprint for .Parameter.Add?
| | Date: Thu, 13 Nov 2003 12:42:59 -0600
| | Lines: 39
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Message-ID: <uZ**************@TK2MSFTNGP10.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.languages.vb
| | NNTP-Posting-Host: 0-1pool36-7.nas14.milwaukee1.wi.us.da.qwest.net
| 63.156.36.7
| | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:156600
| | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| |
| | Is there a way to replace the commented out parameter add syntax with a | | single line of code, like the .Parameter.Add("@Letter"...) line below
| (which
| | does not work)?
| |
| | 'Dim prmLetter As New SqlParameter
| |
| | 'With prmLetter
| |
| | ' .ParameterName = "@Letter"
| |
| | ' .SqlDbType = SqlDbType.Char
| |
| | ' .Direction = ParameterDirection.Input
| |
| | ' .Value = chrLetter
| |
| | 'End With
| |
| |
| |
| | With cmd
| |
| | .CommandType = CommandType.StoredProcedure
| |
| | .CommandText = "GetMasterIndexRowsWithLetter"
| |
| | .Parameters.Add("@Letter", SqlDbType.Char, 1,
chrLetter)
| |
| | '.Parameters.Add(prmLetter)
| |
| | End With
| |
| |
| |
| | Thanks,
| |
| | Dean Slindee
| |
| |
| |
|

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.