Hi all
I hope someone can shed some light, im confused...
I have a GridView that displays diary data, the grids has a DataBound event handler shown below........
protected void GridView1_DataBound(object sender, EventArgs e) { TextBox1.Text =string.Empty; DateTime DRStart = DateTime.Now; DateTime DREnd = DateTime.Now;switch (DropDownList1.Text) {case"Tonight": DREnd = DateTime.Now.AddHours(23); txt_DRStart.Text = (string.Format("{0:ddd dd MMM}", DRStart)); txt_DREnd.Text = (string.Format("{0:ddd dd MMM}", DREnd));break;
There's a few more case statements but they just change the DRStart.Text and DREnd.text dates to populate the grid with differnet range of dates.
Back over on the Default.aspx page I have an SqlDataSource adaptor which look like this...........
"ResultsSqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT venue, town, artist, date FROM gigs WHERE (town = @dotnet.itags.org.town) OR (venue = @dotnet.itags.org.venue) OR (artist = @dotnet.itags.org.artist) AND (date BETWEEN @dotnet.itags.org.DRStart AND @dotnet.itags.org.DREnd)"> "TextBox1" Name="town" PropertyName="Text"> "TextBox1" Name="venue" PropertyName="Text"> "TextBox1" Name="artist" PropertyName="Text"> "txt_DRStart" Name="DRStart" PropertyName="Text"> "txt_DREnd" Name="DREnd" PropertyName="Text">
I get an 'error on page' from I.E. when I run it but no compiler error.
I've got a hunch that its because the @dotnet.itags.org.DRStart & @dotnet.itags.org.DREnd have been converted to strings in theGridView_DataBound event handler and the Sql SELECT statement cant read them. I just cant figure out how to get these values in the correct format!
Any suggestions
Kind regards
Tino
are you sure the tags(< >) you are writing here are correct?
Check the start and closings of each tag in Connection.
it also seems to me you have to transfer the data in correct format
do this
AND (date BETWEEN Date(@.DRStart) AND Date(@.DREnd))...................
Hi
Sorry the code I pasted was incorrect, i've tried the following but still no joy, same error on page in explorer.........
<asp:SqlDataSourceID="ResultsSqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT venue, town, artist, date FROM gigs WHERE (town = @.town) OR (venue = @.venue) OR (artist = @.artist) AND (date BETWEEN (@.DRStart) AND date(@.DREnd))">
<SelectParameters>
<asp:controlparameterControlID="TextBox1"Name="town"PropertyName="Text"/>
<asp:controlparameterControlID="TextBox1"Name="venue"PropertyName="Text"/>
<asp:controlparameterControlID="TextBox1"Name="artist"PropertyName="Text"/>
<asp:controlparameterControlID="txt_DRStart"Name="DRStart"PropertyName="Text"/>
<asp:controlparameterControlID="txt_DREnd"Name="DREnd"PropertyName="Text"/>
</SelectParameters>
</asp:SqlDataSource>
I get a compile error using this syntax --- BETWEEN (@.DRStart) AND date(@.DREnd))"
So I used 'Configure data source' and it makes it ---BETWEEN (@.DRStart) AND (@.DREnd))" which I assume is the correct SQL syntax for the
BETWEEN statement.
Still getting error though, any suggestions
Tino
Hi,
Based on my understanding, you want to use SqlDataSource to retrieve the data from database. When you run your asp.net application, you get an error message. If I have misunderstood you, please feel free to let me know.
What error message did you get? We can use SqlDataSource wizard to configure correct Sql statement.
For example, there is a table which has two datetime type columns: dateFrom, dateEnd. I want to retrieve the data between some datetime span:
<form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> </asp:GridView> </div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetforumConnectionString%>" SelectCommand="SELECT dateFrom, dateEnd FROM dateTable WHERE (dateFrom BETWEEN @.dateFrom AND @.dateEnd)"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="dateFrom" PropertyName="Text" /> <asp:ControlParameter ControlID="TextBox2" Name="dateEnd" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> </form>
I hope this helps.
0 comments:
Post a Comment