troubleshooting Question

How to generate dynamic SQL queries in Visual Studio 2008 .NET

Avatar of electricd7
electricd7 asked on
.NET ProgrammingASP.NET
11 Comments1 Solution307 ViewsLast Modified:
Hello,

I am very new to ASP.NET but have been doing ASP classic for years.  I am trying to setup my first simple .NET page displaying data from a SQL database.  I am used to do set RS = Server.CreateObject("ADODB.Recordset") and was hoping there was something similar to it in .NET so I could just script in all my SQL calls, but thus far I haven't found it.  So I have created a Repeater and bound it to a datasource which I built using the wizard.  The problem is, I am not sure how to set the query parameters to dynamic values from the QueryString.  Here is the code I currently have.  I would like the query at the end to be the same as the 'sqlquery' variable I built at the top.  Thanks!
<script runat="server">
sub Page_Load
        Dim facilityid As Integer
        Dim cyear As Integer
        Dim cmonth As Integer
        Dim sqlquery As String
        facilityid = Request.QueryString("facilityid")
        cyear = Request.QueryString("year")
        cmonth = Request.QueryString("month")
        sqlquery = "select * from dbo.dashboardview where facilityid=1 and year=2009 and month=2;"
        tb4.Text = sqlquery
    End Sub
</script>
 
 
<html>
<body>
 
<form id="Form1" runat="server">
<asp:TextBox id="tb4" runat="server" />
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
<HeaderTemplate>
<table border="1" width="100%">
  <tr bgcolor="#b0c4de">
  <th>Name</th>
  <th>Numerator</th>
  <th>Denominator</th>
  </tr>
</HeaderTemplate>
 
<ItemTemplate>
  <tr>
    <td><%#Container.DataItem("name")%></td>
    <td><%#Container.DataItem("num")%></td>
    <td><%#Container.DataItem("denom")%></td>
  </tr>
</ItemTemplate>
 
<FooterTemplate>
  </table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:IWT-BaldridgeConnectionString %>" 
    SelectCommand="select * from dbo.dashboardview where facilityid=1 and year=2009 and month=2" >
</asp:SqlDataSource>
 
</form>
 
</body>
</html>
ASKER CERTIFIED SOLUTION
rafayali

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros