I am starting out with ASP.Net. I'm going completely nuts trying to find a simple way to get a simple query out. My requirements are fairly simple, I have a radiobox that selects the server, and I have several text boxes that fill the SELECT parameters. I think I need to create the query in code behind (c#) - that's where I did it anyway. Here is that code.
if (DOB.Length != 0 && txtPersonFirst.Text.Length == 0 && txtPersonLast.Text.Length == 0)
{
query = "select top 100 p.FirstName, p.LastName, " + (blah blah blah)
}
And I got this piece to create the data source.
SqlDataSource SqlDataSource1 = new SqlDataSource(ConnectionString, query);
Beyond this, I'm pretty lost after digging for hours in Stackoverflow and other places.
I know I need some aspx code to fill/populate. Like this works fine:
<asp:SqlDataSource runat="server"
ID="MySource"
ConnectionString="SERVER=xxx;Database=xxx;User ID=xxx;Password=xxx"
SelectCommand="select top 100 p.FirstName, p.LastName FROM Person p">
<SelectParameters>
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView runat="server" ID="grid"
DataSourceId="MySource"
AutoGenerateColumns="true">
</asp:GridView>
But I'm not sure how to populate the connectionstring and the selectcommand from codebehind. Hopefully this is simple! I am coding for ASP.NET 2 for compatibility with IIS 6 - not sure if that is useful info.