Solved

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

Posted on 2014-10-26
6
312 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now