Solved

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

Posted on 2014-10-26
6
316 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
  • 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 33

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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 33

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 33

Author Closing Comment

by:Mike Eghtebas
ID: 40405122
Thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 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