Solved

SQL DataAdapter with parameter

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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: …

744 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

9 Experts available now in Live!

Get 1:1 Help Now