how to add a query to sql datasource using a value from code behind?


I have a value in my web form which is received from previous page and i have a sqldatasource in which i have written the query through the wizard.In this query i want to use where clause which tallies the cavlue from code behind :

the code in code behind is:

value1 = Request("abc")

SqlDataSource1.SelectParameters("fid").DefaultValue = value1

and in source:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoursePortalConnectionString %>"
            SelectCommand="SELECT [topic], [author], [date_entered], [last_modified], [message] FROM [thread_table] WHERE ([forumid] = @forumid)">
                <asp:QueryStringParameter DefaultValue="value1" Name="forumid" QueryStringField="fid"
                    Type="String" />


It does not work.....what am i supposed to do?


11/20/2008 3:11:44 PM 29906 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 21

string strValue = request.QueryString("abc")     //Your QueryString Variable name ;


SqlDataSource1.SelectParameters.ADD("forumid",  strValue);

Don't say thanks rather mark my reply as "Answer" if it helps you ,Doing so u'll get points too
amiT jaiN

C#.NET Articles
11/20/2008 3:25:13 PM

Remove the DefaultValue property from your QueryStringParameter and instead set it programmatically via the SqlDataSource.Selecting event handler something like this: 

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    if (e.Command.Parameters["@forumid"].Value == null)
        e.Command.Parameters["@forumid"].Value = Request["abc"];

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

11/20/2008 3:27:37 PM

 Thanks amit it worked...i have marked the answer too.

11/21/2008 8:43:18 AM

Similar Artilces:

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

How to add users to a SQL Server DB used for authentication using SQL query
Hi, I am looking for a simple way to add users manually to a SQL Server DB (set up using aspnet_regsql.exe) via a SQL query. What are the required values, that have to be set in the different tables? Thanks in advance, Markus By default SqlMembershipProvider calls the aspnet_Membership_CreateUser stored procedure to create a user, you can use T-SQL statment like sp_help aspnet_Membership_CreateUser to learn how to use it.Welcome to my SQL/ASPNET forum for Chinese

SQL Datasource with code behind:
Hi all, I am trying to use a query into the code behind like that: "SELECT SELECT * FROM [ListePage] order by @id desc" the problem is that the errors says that its a non declared for the @id ------------------------------------------------- System.Data.SqlClient.SqlException: Must declare the variable '@id'. ------------------------------------------------- If I try to do this: SqlDataSource1.SelectParameters.Add(new Parameter("@id", TypeCode.String)); SqlDataSource1.SelectCommand = "SELECT * FROM [ListePage] order by @id desc"; In this ...

Accessing SQL datasource selected values in code behind when they're pulled from formview, listview, datagrid, etc..
Hello, In my usage of 2.0 so far I've been having a consistent lack of technique at one particular concept: In my code behind with vb, getting at the values pulled by my sql datasource that are used in my formviews, listviews, etc... What are some of the general techniques to accomplish this? What are the easiest ways? If I try to assign output parameters in my query I get errors because sql doesn't want them being used for the data consuming controls as well as assigning parameters. Lately I've been making the textboxes that are populated by the f...

sql datasource UpdateParameters code behind
 Hi all,i have detailsview bind to sqldatasource (directily) with select and updatecommand. Now i have 3 buttons on my page - resolved, pending, cancelresolved - set status = "success" and comment = "somthing"pending - set status = "inprogress" and comment = "somthing"cancel - shoud close the asppagehow can i set in code behind this updateparameters.DetailsView is bind directly to sqldatasource - in witch event shoud i paste the statement i dont`t know if this is right 'SqlDataSource1.UpdateParameters.Clear()...    &nb...

How can I use SQL queries in code behind.
I've been using ASP.NET (came from classic asp) for about a year now and love how easy it is to code in this new language and how easy it is to bind data to Gridviews etc.  I used to have to create SQL connections in code and then use something like RS("Name") to get the query result field I needed the value of. I need this functionality now in ASP.NET but all the tutorials I have found talk about binding objects to datasources.   I need to perform a sql query in my VB code behind page that will look up a single row from a SQL database t...

SqlDatasource using SQL database query as datasource problem
I have a SqlDatasource that uses a SQL 2005 query as its datasource. I cant get the UPDATE/INSERT/DELETE radio button to enable. The query is made up of 3 relational tables. I have tried including all the primary keys from the tables but to no avail. What am i doing wrong and how do i get the update to work Thanks in advance  thegent38,You can use stored procedures for select, insert and update  <asp:SqlDataSource ID="sdsRadnici" runat="server"           ConnectionString="<%$ conStr %>&qu...

Turning off impersonation on a SQL Server datasource, connecting to datasource using Reporting Services credentials
Dear SQL Server Reporting Services Support Guru, How do we configure Reporting Services such that when it attempts to connect to a datasource (e.g. Microsoft SQL Server datasource), it connects as the service account under which it is running as opposed to the calling user? From our research we were thinking we could try one of two things:  1) change the credential type on the datasource itself so that it does not use Windows Integrated Security and instead connects as itself or 2) change the <identity impersonate="true"> flag in the web.config of the ReportServe...

Datasource Sql query
 Hi, I am a coldfusion developer, but have now moved over to ASP.NET using VS2008 Pro, so trying to learn it quickly. My problem is that I have created a datasource with a simple query and when I run it in the query builder it works fine, however when I run it on the page I get nothing. Here is my query    <asp:SqlDataSource ID="qAllTrucks" runat="server"         ConnectionString="<%$ ConnectionStrings:ConnectionString %>"         ProviderName="<%$ Con...

not using SQL Datasource
How can i fill the gridview control without using SQLdatasource control...wherein i am going to use codes only, i can also add template controls that are bind to a certain field...i have observe is that if i use an sqldatasource, & then if i put an additional field in a SELECT QUERY statement, it is like its back to the beginning, all my templatecontrols are goneez Hi~ When you change the schema in data source or refresh it, data presentation will ask you whether to generate columns according to the new schema, just choose 'No'~ Or if you wanna data bind it code beside, that's th...

Using SQL datasource
I just completed my course in 2003. when I work with the VS web developer edition quite confused to write the textbox and dropdownlist data into SQL database. How to define the connection , commandtext and databind with the developer edition. Could any one help with c# coding?...

code for Custom paging without using sqldatasource control and sql datasource control for gridview...........
 code for Custom paging without using sqldatasource control and sql datasource control for gridview...........i need code for how to show all pagenumbers in gridview with custom paging in gridview..............It is very urgent................................. T.Ashok Kumar  suppose that we have a table like thisCountryId  identity intCountryTitle    nvarchar(50)you can use this sql command for paging the dataUSE [CyberOffice]GO/****** Object:  StoredProcedure [dbo].[CountryGetListPaged]    Script Date: 09/17/2008 14:01:06 ******/SET A...

does anybody know where I can learn how to add, update, delete using SQL datasource control?
does anybody know where I can learn how to add, update, delete using SQL datasource control?  I have a couple of books that shows me how to SELECT but nothing shows me how to update, add new record or delete with the SQL data source control. Even this website doesn't have any tutorial. Does any body know where I can read up on how to use all features of this control? Or where that have a couple of examples on how to use it?   You can try out its a great tool for accessing the database. that is a neat tool but they have no examples in the API...

How do I use a SQL query as my report datasource instead of just picking the tables in the database expert?
A colleague of mine has been creating our reports for our application and so far he's been just selecting the tables and setting up the relationships using the database expert (I think). We need to change this so that we can filter the data so we're only reporting on a single account instead of every record in the database. What do I need to change to accomplish this? Can it be done in the report or will I need to create a data source of some kind in the application and pass it into the report somehow? We're new to Crystal Reports so this may be a simple answer. Thanks! You can pa...

Web resources about - how to add a query to sql datasource using a value from code behind? -

Datasource - Wikipedia, the free encyclopedia
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property ...

Inverness Graham Acquires DataSource
Inverness Graham , a lower middle market private equity firm headquartered in suburban Philadelphia, has acquired DataSource , a print supply ...

SmartGlance for iPad for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about SmartGlance for iPad on the App Store. Download SmartGlance for iPad ...

Chaitanya Pandit (@chaitanyapandit) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Data source - Wikipedia, the free encyclopedia
... Data source A data source is any of the following types of sources for (mostly) digitized data: a database in the Java software platform, datasource ...

2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Tagged entries for CLOUD COMPUTING
Alan Williamson's output as a Java Champion, Blog-City Architect, BlueDragon Creator, Author, Speaker and Internet Guru

Private equity deals
... of biometric identity management systems, applications and services. Inverness Graham Investment has acquired DataSource ...

C# C Sharp and Tutorials on C#
Learn the c# langauge to build web applications using our online tutorials with live demos. Participate in our forums and learn from others. ...

JavaScript UI Library, Ajax Components & HTML5 Framework - DHTMLX
DHTMLX offers a rich JavaScript library, UI components & HTML5 mobile framework. Build impressive web apps for both desktop and mobile devices. ...

Resources last updated: 12/9/2015 1:25:33 AM