Solved

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

Posted on 2014-10-26
6
329 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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