I am trying to retrieve data from a database, however I am unable to do that. I am trying to use a SqlDataSource and then either a datareader or dataset to retrieve information. Currently it's set to use a datareader.
I currently have the following code for a SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyLocalSQLServer %>"
ProviderName="<%$ ConnectionStrings:MyLocalSQLServer.ProviderName %>" SelectCommand="SELECT [UserId] FROM [vw_aspnet_Users] WHERE ([UserName] = @UserName)" DataSourceMode="DataReader">
<asp:QueryStringParameter Name="UserName" QueryStringField="UserName" Type="String" />
Once I click a button I run the below code:
System.Data.SqlClient.SqlDataReader reader = (System.Data.SqlClient.SqlDataReader) SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Labelout.Text = reader.ToString();
However reader is always null and I believe it's because I need to send in a value for my query. How do I send the value? I also do not want to "bind" by database. I would also appreciate if someone could tell how to also after retrieving data on how to modify it.