renatois
09-30-2007, 08:01 PM
Hello everyone, I'm having a problem passing a DataTime parameter to a SelectCommand instruction in a DataSource.
I'm using access database and the code is:
<asp:SqlDataSource ID="sdsArtigos" runat="server" ConnectionString="<%$ ConnectionStrings:conArtigos %>"
ProviderName="<%$ ConnectionStrings:conArtigos.ProviderName %>" SelectCommand="SELECT * FROM [Artigos] WHERE ([Status] = ? AND DataInicial <= ?)">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
<asp:Parameter DefaultValue="29/09/2007" Name="Status" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
As you can see the DateTime is hard-coded to work fine but I need it to be dinamic from the SelectCommand, I have tried to replace "29/09/2007" for DateTime.Today but it doesn´t work.
The error I get when I replace 29/09/2007 for DateTime.Today is:
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
Any idea how to solve that problem?
Thanks
I'm using access database and the code is:
<asp:SqlDataSource ID="sdsArtigos" runat="server" ConnectionString="<%$ ConnectionStrings:conArtigos %>"
ProviderName="<%$ ConnectionStrings:conArtigos.ProviderName %>" SelectCommand="SELECT * FROM [Artigos] WHERE ([Status] = ? AND DataInicial <= ?)">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
<asp:Parameter DefaultValue="29/09/2007" Name="Status" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
As you can see the DateTime is hard-coded to work fine but I need it to be dinamic from the SelectCommand, I have tried to replace "29/09/2007" for DateTime.Today but it doesn´t work.
The error I get when I replace 29/09/2007 for DateTime.Today is:
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
Any idea how to solve that problem?
Thanks