Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL DataAdapter with parameter

Posted on 2011-09-09
2
Medium Priority
?
219 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
[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
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

719 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