Solved

Add(String, SqlDbType, Int32, String)    ADO.NET

Posted on 2014-10-26
6
324 Views
Last Modified: 2014-10-26
at: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection(v=vs.110).aspx 

(SqlParameterCollection Class)

In method "Add(String, SqlDbType, Int32, String) " what is parameter number 4 (String) used for?
                                  1             2                3         4

Could you please substitute ? in the following line for parameter number 4?
cmd.Parameters.Add("@FirstName", SqlDbType.Varchar, 30, ?)
                                                     1                                 2                3   4

Question: What is String parameter is for?
                                     4?
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40404776
From your link with a highlight added:
public SqlParameter Add(
      string parameterName,
      SqlDbType sqlDbType,
      int size,
      string sourceColumn
)

sourceColumn
    Type: System.String

    The name of the source column (SourceColumn) if this SqlParameter is used in a call to Update.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 150 total points
ID: 40404950
Said otherwise, if you use a DataAdapter to update your database after changes in a DataTable, and if you provide your own SQL command to do it instead of using a SqlCommandBuilder, you use that fourth argument to specify which column in your DataTable will provide the value for that parameter.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40405045
In this particular case, SourceColumn is specified SQL Server based Proc. I was hoping it could be handling the pram value as for combine one liner for the following lines:

With SQL
            .AddSpPram("@FirstName", SqlDbType.VarChar, 30)
            .AddSpPramValue("@FirstName", FirstNameTextBox.Text)
            .
End With

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 44

Accepted Solution

by:
AndyAinscow earned 350 total points
ID: 40405090
>>In this particular case, SourceColumn is specified SQL Server based Proc.
? What do you mean, that is not what the documentation says (unless I totally misunderstand it).

>>I was hoping it could be handling the pram value as for combine one liner for the following lines:
This is from the link you posted:
categoriesAdapter.SelectCommand.Parameters.Add( "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
Isn't that what you want to do in one line ?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40405112
Hi Andy,

I agree with your statement on SourceColumn issue. What I meant to say was I do not need to use in the case of stored proc because it is given in the proce itself. Also, keep in mind I am new to all this and I might say something off the wall at times. I will take your feedback as correction to my statement.

Yes, .SelectCommand.Parameters.Add( "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters"; is wonderful

brb
0
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 40405122
Thank you.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question