.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to change selectcommand in sqldatasource

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :ASP.Net

hi there, 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 Complete Post

More Related Resource Links

SqlDataSource how to change the stored procedures at run time



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?



dropdownlist bound to sqldatasource adds items instead of replacing on change



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:

 <asp:DropDownList ID="ddlMajor" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource1" DataTextField="majortext" 
      DataValueField="majorkey" AppendDataBoundItems="True" AutoPostBack="True">
         <asp:ListItem Value="0">Select Major</asp:ListItem>
<asp:DropDownList ID="ddlReq" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource2" DataTextField="req" DataValueField="admreqkey" 
            AppendDataBoundItems="True" AutoPostBack="True">
                <asp:ListItem Value="0">Sel

Change Sqldatasource or LINQ to SQL into a DataSet? [C#]

Hi Everyone,I've saw a couple of threads on here and on different sites around this area but none I've tried have seemed to work.What I'm struggling to achieve is, I want to take a set of results attained by either a SqlDataSource or a LINQ to SQL Method and feed them into a DataSet. Why? This is because I have downloaded an example of a repeater which has paging programmed on it, but in the example it uses the DataSet.ReadXML method to read a pre-defined set of results in an XML file. As my results are constantly changing I thought it would be a good idea for the DataSet to attain them from the previous mentioned ways.I've lost count at the number of ways I've tried it, from setting up SQLConnection method seperately and the QS set as a 'string' then passing that through etc. to simply trying Dataset Items = PartialClass.GetAll(); - Which throws back Generic<List> cannot be converted to DataSet - or something close to that.I'm working from an example and incorporating it into my own project.Below is the code I'm trying to get working:C#:protected void Page_Load(object sender, EventArgs e) { // Call the ItemsGet method to populate control, // passing in the sample data. ItemsGet(); } public void ItemsGet() { // Read sample item info from XML document into a DataSet DataSe

sqldatasource with Inner Join SelectCommand....

I have a gridview with a sqldatasource with SelectCommand as below:"SELECT DISTINCT pr1.ID, pr1.Candidate_Code, pr1.Desc2 AS Name_EN, pr2.Desc2 AS Name_CN FROM Table1 pr1 INNER JOIN Table1 pr2 ON pr1.Candidate_Code = pr2.Candidate_Code AND pr1.Stat1=pr2.Stat1 AND pr2.Desc1 = 'NAMA (CINA)' WHERE pr1.SESSIONS = @Sessions and pr1.DUN = @Dun AND pr1.Stat1 = 'M' AND pr1.Desc1 = 'NAMA (ENG)'" Hw can set the UpdateCommand to update pr1.Candidate_Code? I have tried "UPDATE SPR_Candidate_Profile2 SET Candidate_Code = @Candidate_Code WHERE ID = @ID AND Candidate_Code = @Candidate_Code" but it's not workling.....

Modifying the SqlDataSource SelectCommand prior to loading a page


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:

    <asp:ScriptManager ID="ScriptManagerCustomerMaintenance" runat="server" EnablePageMethods="true"></asp:ScriptManager>
    <asp:SqlDataSource ID="SqlDataSourceHD" runat="server"
        ConnectionString="<%$ ConnectionStrings:HDOracleConnectionString %>"
        ProviderName="<%$ ConnectionStrings:HDOracleConnectionString.ProviderName %>"
        SelectCommand="SELECT * FROM Customer WHERE (HOME_PHONE=:HOME_PHONE)"
        UpdateCommand="UPDATE Customer SET CustomerEID=:Cu

How to change this code to get data from sqldatasource control instead of a list


I have googled a relevant code for my control on ASP.net page but it get data from a har code list. How to modify the code so it get the data from the sqldatasource which I have already built instead of getting data from the list?


protected void calDT_DayRender(object sender, DayRenderEventArgs e)


        if (dtholidays.Contains(e.Day.Date))


            e.Day.IsSelectable = false;




private List<DateTime> GetPublicHolidays()


        List<DateTime> list = new List<DateTime>(); 

        //populate from database or other sources

        list.Add(new DateTime(2010, 01, 01));

        list.Add(new DateTime(2010, 02, 02));

        list.Add(new DateTime(2010, 02, 14));

        list.Add(new DateTime(2010, 03, 02));


Dynamically changing SqlDataSource.SelectCommand from FormView.ModeChanged


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).

<%@ Page Language="VB" AutoEventWireup="false"   %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<script runat="server">

    Private Shared FormMode As String
    Private Shared ParentSrID As Integer
    Private Shared SRRow As DataRowView
    Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim button As String = GetPostBackControl(Me).ID
        Select Case button
            Case "EditButton"
                FormMode = "Edit"
            Case "UpdateButton"
                If Not frmSR.CurrentMode = FormViewMode.Edit Then
                    Catch ex As HttpException
                    End Try
                End If
            Case "CancelButton" 'Cancel SR Add/Edit
        End Select
    End Sub
    Protected Sub frmSR_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles frmSR.DataBound
        'We want to use the current record

How to Localize Windows Forms and Change the Language at Runtime

Localization is the process of customizing your application to a particular language, culture or locale. Visual Studio provides support for localizing Windows Forms with much ease. In this article, we will see how to localize windows forms and give the user the ability to change to his preferred language at runtime.
When you run a localized application, the appearance is determined by two culture values. The UICulture property is used to specify which resource files will be loaded for the form. The Culture property, on the other hand, determines how strings such as dates, numerals, and currency amounts are formatted.
Let us see the steps required to create a localized form. You can then expand this example and adopt the same approach for the rest of the forms in your project

Selected to change the background color of the page



As this site, http://www.borfin.com.tr/genel/Default.aspx, How can I change the background color selected pages.

Bug: Does not change column type from nvarchar to ntext


Scenario: If you create a table with a column of type nvarchar, populate it with some content and try to modify it using the WebMatrix editor, from nvarchar to ntext, it does not display any error message or warning that this is not possible. It silently saves and reverts the change, back to nvarchar. Wasted some hours on this issue as I thought my column was ntext, but in fact was still nvarchar.

Expected behavior: It should change to ntext, or if SQL CE doesn't support that, it should notify the user that no change was applied.

How to change the default page base class?


I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.



How to retrieve data from SqlDataSource and pass to a variable?


Hi there,

I have a page in my website where there is very little code-behind. I only have two lines of code in Page_Load() and the rest of the code is declarative ASP.NET code. I have a FormView control which uses a SqlDataSource to get some order information. The SqlDataSource calls a stored procedure called usp_GetOrderDetails, here's the code for the SqlDataSource:

    <asp:SqlDataSource ID="sdsFormOrderDetails" runat="server" 
ConnectionString="<%$ ConnectionStrings:ForexDB %>"
ProviderName="<%$ ConnectionStrings:ForexDB.ProviderName %>"
SelectCommand="usp_GetOrderDetails" SelectCommandType="StoredProcedure"
UpdateCommand="usp_UpdateOrder" UpdateCommandType="StoredProcedure"
<asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedDataKey.Value" />
<asp:ControlParameter Name="orderId" ControlID="frmOrderDetails" PropertyName="SelectedValue" />

Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

SqlDataSource UpdateCommand using 2 tables


I have two tables

Trans  with fields TransID, Date, CustomerID and some other stuff

Customer with fields CustomerID, Name, TaxId

On the screen the user only sees the fields Date and Customer Name. CustomerID is behind the scenes only.


I'm using SqlDataSource. Having no problems with SelectCommand. I don't know how to construct the UpdateCommand and InsertCommand.

Let's say the user changes the date, then I need to do an UPDATE.

UPDATE Trans SET Date = @Date, CustomerID = @CustomerID results in an error message and the record is not updated.

I get an error on the page that says "Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in correct format".


I tried taking out the set for CustomerID and I still get the error on page.


Also, for inserting, the users will see a dropdownlist with Customer Names. I need to convert that to a CustomerID to be used in the new record being inserted in the database. I'm not sure how to do this.


Do I need to do something with Control Parameters?

Change Button Text in Multi Language Website


Hi i developing multi language website

using Master pages

everything fine

Page_Load i set the Text property of Button Control from Resource file

like this

Button1.Text = GetLocalResourceObject("Button1")

then in the button click event i cnage the text of the Button control

Button1.Text = GetLocalResourceObject("Button1_new")

but the text doesn't change and no error messgae

what is the problem how to solve this


How to change text in columns in SSRS?


I need to create a complex report and export it to Excel. 

In the first column header, text is displayed as "Hide Daily Columns", but I need the text to change as "Unhide Daily columns" when I click on it and when the text changes the columns under "daily" header (I have 3 columns under this header) present in the report shud be hidden and only weekly columns shud be visible. Any ideas please. I am new to SSRS and tried out many ways but didn't get it.

dynamically change column names in Crystal reports


I need to develop 3 pages.

On the first page user defines atmost 7 column names to be displayed on the report. I'm saving these names in a Sql DB table 'Columns' with Column_Nm and Column_ID as Table columns.

On the second page I'm retrieving column_Nm from the table and displaying them on the page so that the user enters the data. This data is saved in another table 'Summary' with the Columns column1 through column7.

on the 3rd page I need to show a report of 'Summary' table.

How do I dynamically replace column1 through column7 names with that of 'Column_Nm' on the report?

Any help/suggestions would be appreciated.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend