Solved

SQL DataAdapter with parameter

Posted on 2011-09-09
2
215 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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