Solved

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

Posted on 2014-10-26
6
305 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

11 Experts available now in Live!

Get 1:1 Help Now