How would i get a variable value out of a sqldatasource

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">
            <DeleteParameters>
                <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!
bmanmike39Asked:
Who is Participating?
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
GavinMannionCommented:
At a quick glance could you not just have

SqlDataSource1.SelectParameters["Genera"].DefaultValue; //You might need the @ sign but I don't think so
0
 
bmanmike39Author Commented:
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”
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
GavinMannionCommented:
Hmm,

As I said a quick glance ;)... That is strange though, let me have a think and see if anyone else knows?
0
 
Jason ScolaroCommented:
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
0
 
bmanmike39Author Commented:
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
0
 
GavinMannionCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.