DataSource Controls :: How To Change Selectcommand In Sqldatasource

Oct 11, 2010

i have an SQLdatasource in my page

i was trying to modify it as:

SQL.SelectCommand = "Select * from " + TXT_Tabella.Text;

because i want update dinamically my sql server tables but ,every time i am going to sort, or change page the selectCommand returns as before!

viewState is true! how can i have an SQLdatasource dinamyc by tableName? and how this problem occurs?

View 3 Replies


Similar Messages:

DataSource Controls :: Sqldatasource With Inner Join SelectCommand...

Sep 4, 2010

I have a gridview with a sqldatasource with SelectCommand as below:

[Code]....

but it's not workling.....

View 1 Replies

DataSource Controls :: Modifying The SqlDataSource SelectCommand Prior To Loading A Page?

Sep 28, 2010

I have a SqlDataSource setup in the markup on my page. After some new requirements, I am trying to find a way to modify the SelectCommand before the data is filled for the first time. The SelectCommand below will now be used by default since we'll always have the first param. I am faced with a need to modify the SelectCommand though, adding a second session parameter along with it. I tried to override the OnInit method but it didn't seem to help...it still used the default query. Is there a best way to accomplish this? Here is the section of markup I am referring to:

[code]....

View 2 Replies

DataSource Controls :: Dynamically Changing SqlDataSource.SelectCommand From FormView.ModeChanged?

Nov 17, 2010

In an asp.net 3.5 web app, I have a page with the following markup/code (this is the brief version, but I believe I got all the relevant info).

[Code]....

The form contains 2 different record types, accessed using the paging controls, depending on the ParentSR field; a parent SR will be something like '1234' while its sub-record will be something like '1234.1'. There are only a few differences in the fields used between the 2 different record types and that is why they are stored in the same table. However, the activity depends on the record type. When browsing from the parent record to the sub-record, the itemtemplate loads fine (notice in the formview's datasource
query, that the sractivity_id field is being pulled along with the subquery value). But when going to edit the record, the page throws an error:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentOutOfRangeException: 'ddlActivity' has a SelectedValue which is invalid because it does not exist in the list of items.

If i click 'back' and retry, it may take 3 attempts, but then the edittemplate will load just fine. I should also point out that this error does not always occur. I've been trying to figure this out for a couple months and it is driving me nuts, mainly due to the fact that I can't reproduce the error in development--it seems to only occurr in production. Anyone with any thoughts on what is going on?

View 1 Replies

Forms Data Controls :: DataList And SqlDataSource SelectCommand?

May 27, 2010

In my application, I am using DataList. In Item Template I added One GridView and SqlDataSource to populate data in GridView. DataList having one DataKey field, I want to pass this DataKey Value to the SqlDataSource as Parameter.

I tried this by Using Following:

<SelectParameters>

View 2 Replies

Forms Data Controls :: Can't Edit/delete With Gridview Using Dynamic Sqldatasource.selectcommand

Feb 2, 2010

With asp 2.0 and vwd 2005, I have a page with a radiobuttonlist, textbox and gridview with edit/delete. Using the radiobuttonlist, the user selects a search type and then enters the criteria in the text box. the click event of a submit button checks the rbl.selectedindex and chooses a sqldatasource.selectcommand with the where clause getting its criteria from the textbox. The gridview loads the data, but the edit/delete are not working. Code and relevant markup is below

[Code]....

[Code]....

[Code]....

View 3 Replies

DataSource Controls :: SqlDataSource How To Change The Stored Procedures At Run Time

Aug 18, 2010

Is it possible to change the select, insert and update stored procedure of an SqlDataSource at run time. I don't mean to change the definition of the stored procedure, but I mean to change the assignment, i.e. To change the select stored procedure from "selectSP1" to "selectSP2" at run time. Is it possible?

View 4 Replies

What Dynamic SelectCommand In SqlDataSource

Nov 17, 2010

I have a DDL with 2 options: "Trainer" & "Observer." I'd like to use the selection from that DDL to reference a field in the SqlDataSource SelectCommand.

There are 2 fields in the table that may be referenced in the SelectCommand:

"Trainer_Oracle_ID" & "Observer_Oracle_ID." I'm trying to do something like:

WHERE @Oracle_ID_Type = <%=DropDownList_Oracle_ID_Type.Text%>_Oracle_ID

i.e. User selects "Trainer" and the SelectCommand references the field called:

"Trainer_Oracle_ID."

View 6 Replies

Using Parameters To Configure The Table Name In An SqlDataSource SelectCommand?

Dec 15, 2010

I have an ASP.NET 3.5 web form with a DropDownList bound to a table of company names in a database. I also have a data bound GridView which I would like to update with data from the database depending on the company name selected in the DropDownList, so that the SelectCommand for the GridView's SqlDataSource is:

SELECT Registration, Telephone, Profile FROM {CompanyName}_VehicleData

Where {CompanyName} is whatever is selected in the DropDownList. I've used the Command and Parameter Editor to create a ControlParameter pointing to the SelectedValue of the DropDownList, but I don't know how to write the SelectCommand query to concatenate the parameter to '_VehicleData'.

View 1 Replies

Changing SqlDataSource.SelectCommand At Runtime Breaks Pagination?

Jul 23, 2010

I have a GridView bound to a SqlDataSource with a default SelectCommand defined as such:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:MyConn %>"
ProviderName="MySql.Data.MySqlClient"
SelectCommand="select * from blah blah" />

There are cases where I have to change this query dynamically at runtime, so I do the following:

SqlDataSource1.SelectCommand = sql; // 'sql' is the new query
GridView1.PageIndex = 0;
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;
GridView1.DataBind();
updatePanel.Update();

This works just fine actually, but when I click the pagination controls, the result set defaults back to the SelectCommand defined in the SqlDataSource1.

View 2 Replies

DataSource Controls :: How To Get Sqldatasource1.selectCommand Value

Mar 30, 2011

How to get sqldatasource1.selectCommand value

[Code]....

i want to set that if nothing return i will display a msg to users.

View 7 Replies

DataSource Controls :: Passing A Variable In A SelectCommand?

Jul 7, 2010

I am trying to pass a variable within a selectcommand statment in ASP.NET and I have researched online how to do it but I can't seem to find a way to do it...What I am trying to do is write a code for a web page that will display a page with useful links on it where the links are separated into different topics and where everything is dynamically grabbed from a database. This is what I have so far:

<!-- Start MainContentRegion -->
<h1>Useful Links</h1>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"

[]code...

View 4 Replies

DataSource Controls :: SelectCommand String Is Too Long?

Dec 21, 2010

My SelectCommand string in my asp:SqlDataSource is very long. Is there a way I can chop it up into different strings on several newlines to make it more readable?

View 4 Replies

DataSource Controls :: SQLDataSource And Tie A SqlDatasource To A Stored Procedure

May 14, 2010

I am trying to tie a sqlDatasource to a Stored Procedure. The stored procedure looks like...

[Code]........

View 2 Replies

DataSource Controls :: Pass QueryString In SelectCommand From Code Front?

Jan 7, 2011

I have a question related to <asp:SqlDataSource's SelectCommand. How to pass a querystring like <%# Eval("PhotoID") %> in the selectCommand. The whole frontend code is attached. I put

<%# Eval("PhotoID") %> and the photoid gets printed in the page.
<%# Eval("PhotoID") %> is the current displayed picture's PhotoID.

I want to pass this PhotoID or I want to pass <%# Eval("PhotoID") %> to the select command dynamically. I have tried the following approaches:

1) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = @pID"> <SelectParameters><asp:Parameter Name="pID" DefaultValue="7" /></SelectParameters> </asp:SqlDataSource> The above works but it gives only information about PhotoID 7, but there are other photos; How to set pID's value to <%# Eval("PhotoID") %> in ASP .NET's frontend page? then I also tried,

2) <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetdb %>" SelectCommand="SELECT UserName, commentDesc, uID FROM photo_comment_view Where pID = <%#'Eval("PhotoID') %>"></asp:SqlDataSource> Gives Parser error: Parser Error Message: The server tag is not well formed.

What I should do so that I can pass current PhotoID to SelectCommand? The frontend code:

<%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Your Name Here | Picture Details"
CodeFile="Details.aspx.vb" Inherits="Details_aspx" %>
<asp:content id="Content1" contentplaceholderid="Main" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="shim solid"></div>
<div class="page" id="details">
<%--Update Panel Here--%>
<asp:UpdatePanel runat="server" ID="updatepanel">
<ContentTemplate>
<asp:formview id="FormView1" runat="server" datasourceid="ObjectDataSource1" cssclass="view"
borderstyle="none" borderwidth="0" CellPadding="0" cellspacing="0" EnableViewState="false" AllowPaging="true">
<itemtemplate>
<div class="buttonbar buttonbar-top">
<a href="Albums.aspx"><asp:image ID="Image1" runat="Server" skinid="gallery" /></a>
<asp:ImageButton ID="ImageButton9" Runat="server" CommandName="Page" CommandArgument="First" skinid="first"/>
<asp:ImageButton ID="ImageButton10" Runat="server" CommandName="Page" CommandArgument="Prev" skinid="prev"/>
<asp:ImageButton ID="ImageButton11" Runat="server" CommandName="Page" CommandArgument="Next" skinid="next"/>.................

View 14 Replies

DataSource Controls :: How To Create A Query In Gridview Selectcommand Without The Code Behind

Dec 1, 2010

how to query the system date in selectcommand in gridview without using the codebehind. using c# .net

my code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM tablename where date_today = <SYSTEMDATE>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName
%>"

View 1 Replies

DataSource Controls :: Maintaining A Custom SelectCommand Across Page Loads?

Feb 19, 2011

My SqlDataSource has no selectCommand defined in the .aspx page. Instead I define it in the code behind dynamically depending on some parameters that the user selects and then clicks a button to perform the query (custom search filters basically). The problem is that when I click on a different page in my dataPager, or I click to sort any of the columns the gridview becomes empty when the page refreshes. I did a check and the selectCommand becomes empty when the page posts back. Is there a way to prevent this from happening?

View 2 Replies

DataSource Controls :: Filter - Select Date In Ddl And Use Selectedvalue In Gridview SelectCommand

Nov 7, 2010

I've got a gridview which works fine. I use dropdownlists which are filled with distinct values of the columns. So when I select an item in a drompdownlist the gridview refreshes based on the selected value. When I have a column which uses string values, I can start the filter with a default % value to use in my select paramaters. But when I have a date column, I can't use that. I use a datasource for the gridview and I prefer to leave codebehind out if this is not needed. Now I use >= in my gridview select to show all rows. but I want to use only = to make the filter work correct when I select a date in the ddl and use the selectedvalue in the gridview selectCommand

<asp:DropDownList ID="ddlUpdateDatum" DataSourceID="dsPopulateUpdateDatum"
AutoPostBack="true" DataValueField="UPDATEDATE" runat="server"
CssClass="selectinput" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="01/01/1900"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsPopulateUpdateDatum" runat="server"
ConnectionString="<%&#36; ConnectionStrings:GAMSYSTEMSqlServer %>"
SelectCommand="SELECT DISTINCT(UPDATEDATE) FROM [messages] ORDER BY UPDATEDATE ASC ">
</asp:SqlDataSource>
And I use this in the gridview datasource:
<asp:SqlDataSource
runat="server"
ID="dsGridview"
ConnectionString="<%&#36; ConnectionStrings:DBSqlServer %>"
SelectCommand = "SELECT * FROM [messages] WHERE AND UpdateDatum >= @UpdateDatePar ORDER BY UpdateDatumDESC"
>
<SelectParameters>
<asp:ControlParameter Name="UpdateDatePar" ControlID="ddlUpdateDate" PropertyName="SelectedValue" Type="string" />
</SelectParameters>

View 2 Replies

DataSource Controls :: Dynamic SelectCommand Won't Be Passed After Partial Page Update?

Mar 11, 2010

I have a page has Listview and Datapager inside UpdatePanel. When I refresh the new SQL results and bind by pressing link buton outside of the update panel, I get correct results. (get new SQLselect statment, rebind to listview, update updatepanel)

However, the SelectCommand is not bound right or some other reason, if I press datapager, I won't get no results.

I'm guessing it's caused by not passing new dynamic selectcommand since my datapager and listview works first update.

View 4 Replies

DataSource Controls :: Sqldatasource Insert Method - Copy Data To The Other Datasource By Selecting Checkbox

Feb 25, 2010

i have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.

At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?

View 1 Replies

Forms Data Controls :: Change SqlDataSource For Combo Box In C#?

Dec 13, 2010

I have two SqlDataSources in my page for a combo box. One loads all the data from a table, and the other one will preselect the combo box data when editing the page record.

View 1 Replies

Forms Data Controls :: Gridview Columns Change After New Sqldatasource Changed In Code?

Feb 14, 2010

I have a gridview that loads with a new datasource on button click event. On the gridview (which is located in a table columm incidentally) are 2 columns, a descriptor and a checkbox. The problem is that after postback, the column widths change, the checkbox column expands and the other column contracts. Is there a way to keep the gridview column sizes the same after postback?

View 2 Replies

Forms Data Controls :: Dropdownlist Bound To Sqldatasource Adds Items Instead Of Replacing On Change?

Aug 26, 2010

I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:

[Code]....

Do I need to do something on selectedindexchanged to somehow "clear out" the previous datasource? I can't find anything about this online, although one person seemed to suggest it was related to using a master page. (which I am using).

View 3 Replies

DataSource Controls :: SqlDataSource With A Lot Of Parameters?

Sep 4, 2010

I have asked similiar question before where I have two control on the page header says "username" and "gender". User can select both the control or either one and the page will execute searching based on the criteria supplied. So if username supplied

SELECT * FROM [this_table] WHERE username = @username
and if gender supplied
SELECT * FROM [this_table] WHERE gender = @gender
and if both supplied
SELECT * FROM [this_table] WHERE username = @username AND gender = @gender

I know this sounds not very complicated but in my case, I am having like more than 10 controls up there. It is something likeusername, gender, age, date of brith, title, father name, frst name, last name, blur blur blur and it's a lot then I started to lost. if i were to use if else caluse on code-behind and produce query, it would end up writing a lot of if-else and if i use stored procedure (with if-else) then my stored procedure would contains a lot of if-else statement. I am fairly new to this concept and if I'm on the wrong track, please correct me. Is there any better way to save my hair without actually going through each
if-else statement to build the query ?p.s. I'm using GridView and SqlDataSource command to display the result back on .aspx page.

View 2 Replies

DataSource Controls :: Can Use If Else In Sqldatasource If Else Parameters

Oct 4, 2010

I am trying to check whether a username exists in my database before inserting the new row & display a message to the user if it does.

On my SqlDataSource my InsertCommand looks like this:

InsertCommand="IF NOT EXISTS (SELECT * FROM Users WHERE UserName = @UserName) BEGIN INSERT [Users] ([UserName], [FirstName], [LastName], [City], [State], [Country], [CompanyName], [Active], [PasswordHash]) VALUES (@UserName, @FirstName, @LastName, @City,
@State, @Country, @CompanyName, @Active, @PasswordHash) END"

This works as expected: If the username is unique, the row is created.

If the username already exists, the row is not added.

The problem is, if the row already exists, the insert is rejected but the user is not notified.

So my question is, is there a way I can notify the user?

Maybe something like: InsertCommand = "If Not Exists (select....) Begin Insert...Else Notify User Somehow End This is a basic database, I'm not using the built-in membership provider nor will be.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved