How would i get a variable value out of a sqldatasource

Posted on 2006-05-02
Medium Priority
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

ID: 16593984
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

ID: 16596464
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

ID: 16596535

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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 22

Expert Comment

by:Jason Scolaro
ID: 16604788
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

ID: 16606717
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

ID: 16607387
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

GranMod earned 0 total points
ID: 16629047
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

621 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