Reputation: 640
I want to populate a Label using a stored procedure from a SQL data source. My stored procedure takes two parameters but I dont know how to call it.
My table is similar to this:
CityID CityName London Paris
----------- -------------------- --------------------------------------- --
1 London 0 60
2 Paris 50 0
3 Berlin 90 60
4 Madrid 150 90
5 Dublin 30 80
6 Rome 75 88
My intention is to return a value based on what cities are selected from 2 separate drop down lists. e.g London, Paris would return 60
It seems that I have the data source set up
<asp:SqlDataSource ID="JourneyPrice" runat="server"
ConnectionString="<%$
ConnectionStrings:connectToEnterpriseAssignmentDB %>" SelectCommand="GetBusPrice"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlDepart" Name="city" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlDestination" Name="column" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
My c# code is :
DataView dataViewJourneyPrice = (DataView)JourneyPrice.Select(DataSourceSelectArguments.Empty);
if (dataViewJourneyPrice != null)
{
if (dataViewJourneyPrice.Count > 0)
// Whatever column is coming from database
lblPrice.Text = dataViewJourneyPrice.ToString();
}
}
This is not yielding the correct results
Solved:
labelBusPrice.Text = dataViewJourneyPrice[0]["ColumnName"].ToString();
Upvotes: 1
Views: 786
Reputation: 13179
You just need to pull the value from the data view. Once you correct the column name, you may want to cast it to whatever the true data type is so you can do proper formatting before putting into your label.
if (dataViewJourneyPrice.Count > 0)
// Whatever column is coming from database
labelBusPrice.Text = dataViewJourneyPrice[0]["ColumnName"].ToString();
Upvotes: 1