Solved

SQL DataAdapter with parameter

Posted on 2011-09-09
2
214 Views
Last Modified: 2012-05-12
I have a sqldatasource that needs a parameter passed to it.

the attached is not working.  

ideas?

thanks
Session["PID"] = lbx_PIDs.SelectedValue.ToString();

SqlDataAdapter da = new SqlDataAdapter(sds_DataForPID.SelectParameters.Add("@PID", TypeCode.Char, Session["PID"].ToString()), sds_DataForPID);

Open in new window

0
Comment
Question by:gdspeare
2 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 36513686
Do you have the parameter already defined in the front end?

sds_DataForPID.SelectParameters["PID"].DefaultValue = lbx_PIDs.SelectedValue.ToString();

0
 
LVL 1

Accepted Solution

by:
Temizh earned 500 total points
ID: 36514140
SqlDataAdapter has not any constructor takes parameters.

            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand sqlCommand = new SqlCommand("Select * from table where id = @pid", sqlConnection);
            sqlCommand.Parameters.AddWithValue("@pid", value); // "@pid" or "pid"
            SqlDataAdapter sda = new SqlDataAdapter(sqlCommand, sqlConnection);

through the SqlCommand with Parameter.Add you can pass your parameters.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What's the most efficient way to load up a couple of large table in C#? 5 45
Run time Error 4 47
SSRS subreport with parameter 3 29
VB.NET 2008 - SQL Timeout 9 23
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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