How would i get a variable value out of a sqldatasource

Posted on 2006-05-02
Last Modified: 2008-01-09
How can i get a variable value out my SqlDataSource.
Step by step this is what i am trying to do.

1.     I have a SqlDataSouce
2.     it has a @Genera variable in it.
3.     i would like to store this variable in a different variable named GeneraType.

I am new to asp and have tried a number of thing but with no success. I can figure out the code

This is what i have for code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            DeleteCommand="DELETE FROM [SongsCW] WHERE [songID] = @songID" InsertCommand="INSERT INTO [SongsCW] ([uNameID], [createdatetime], [Genera], [sName], [sAlisName], [notes], [userName], [ANA]) VALUES (@uNameID, @createdatetime, @Genera, @sName, @sAlisName, @notes, @userName, @ANA)"
            SelectCommand="SELECT * FROM [SongsCW]" UpdateCommand="UPDATE [SongsCW] SET [uNameID] = @uNameID, [createdatetime] = @createdatetime, [Genera] = @Genera, [sName] = @sName, [sAlisName] = @sAlisName, [notes] = @notes, [userName] = @userName, [ANA] = @ANA WHERE [songID] = @songID" OnSelected="SqlDataSource1_Selected">
                <asp:Parameter Name="songID" Type="Int32" />

code behind lag C#

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        string GeneraType;

Thanks in advance for any help!
Question by:bmanmike39
    LVL 15

    Expert Comment

    At a quick glance could you not just have

    SqlDataSource1.SelectParameters["Genera"].DefaultValue; //You might need the @ sign but I don't think so

    Author Comment

    Thank you,  I tried this but i get the following error on the SqlDataSource1!

    “ Only assignment, call, increment, decrement, and new object expressions can be used as a statement”
    LVL 15

    Expert Comment


    As I said a quick glance ;)... That is strange though, let me have a think and see if anyone else knows?
    LVL 22

    Expert Comment

    I'm not sure I understand what you're trying to do.  First of all the code that you show is the Selected event, which runs after the SelectCommand has been processed, but this command doesn't have any reference to @Genera, only the Insert and Update commands do.

    You have to pass in the values from somewhere for those variables, where are they coming from -- server controls?

    I guess I'm just missing something.. help me, help you.
    -- Jason

    Author Comment

    I got the answer,  this is what I have do:

    DataView Getyp = ((System.Data.DataView) (SqlDataSource1.Select(DataSourceSelectArguments.Empty)));

    Label1.Text = Getyp.Table.Rows[0][“Genera”].ToString();

    Thank for the help anyway
    LVL 15

    Expert Comment

    Ah well spotted Scolja, I got confused because the UpdateCommand is on the same line.

    Basically what bmanmike39 was looking for is the field Genera as far as I can see.
    Which is entirely different from what I was trying to do :)

    Well worked out bmanmike39.
    When you ask for this question to be closed please ask them to PAQ it as it is something people often look for.

    Apologies for missing your original question.

    Accepted Solution

    Closed, 500 points refunded.
    The Experts Exchange
    Community Support Moderator of all Ages

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    728 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

    22 Experts available now in Live!

    Get 1:1 Help Now