473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataSource: No valid declarative parameter value for a datetime?

I've been going around and around on this one. I can't believe that it is
"by design" as Microsoft says.

Here's the situation:

In *declarative* syntax, I'm trying to create a default datetime value for a
SqlDataSource parameter. (I know how to insert this parameter in code. I
want to use declarative markup.)

Here's the declarative markup with ???????? indicating where I'm stumped.

<insertparamete rs>
<asp:paramete r Name="Title" Type="String"/>
<asp:paramete r Name="Descripti on" Type="String" />
<asp:Paramete r Name="DateAdded " Type="DateTime" DefaultValue="? ???????" />
</insertparameter s>

There's a bug report on this dating back to 2004 from my MVP colleague
Frederik Normen. Here's the reply to the bug from the Web Platform and
Tools Team.

"If you specify a type on a Parameter, that type is used to convert the
DefaultValue or Value of the parameter to an object of that type, then the
object itself is added to the Command's parameter collection and it formats
it as you see it in the trace. If you would like full control over the
format of the date sent to the SQL server, type the parameter as a string
and your string-date will be passed to the SQL server untouched."
So I assume that I'd have to change to using the type as a string. But what
should the string look like now? I've tried lots of combinations but haven't
hit the right one.

<insertparamete rs>
<asp:paramete r Name="Title" Type="String"/>
<asp:paramete r Name="Descripti on" Type="String" />
<asp:Paramete r Name="DateAdded " Type="String" DefaultValue="? ???????" />
</insertparameter s>

I'm hoping that I'm just missing something simple on this and someone will
give me a boot in the right direction.

Ken
Microsoft MVP [ASP.NET]
Jun 16 '07 #1
3 8006
Hi Ken,

I've done some test and it seems it's working on my side when you use:

<asp:Paramete r Name="lastUpdat ed" Type="DateTime" DefaultValue="2 007/12/24"
/>
Here's my test steps:

1) Create a SQLExpress database in VS2005, add a table with three fields:
id, code, lastUpdated.

2) Add a FormView and SqlDataSource to use the table:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="i d"
DataSourceID="S qlDataSource1">
<EditItemTempla te>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%#
Eval("id") %>'></asp:Label><br />
code:
<asp:TextBox ID="codeTextBox " runat="server" Text='<%#
Bind("code") %>'>
</asp:TextBox><br />
lastUpdated:
<asp:TextBox ID="lastUpdated TextBox" runat="server"
Text='<%# Bind("lastUpdat ed") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%#
Bind("id") %>'>
</asp:TextBox><br />
code:
<asp:TextBox ID="codeTextBox " runat="server" Text='<%#
Bind("code") %>'>
</asp:TextBox><br />
lastUpdated:
<asp:TextBox ID="lastUpdated TextBox" runat="server"
Text='<%# Bind("lastUpdat ed") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id")
%>'></asp:Label><br />
code:
<asp:Label ID="codeLabel" runat="server" Text='<%#
Bind("code") %>'></asp:Label><br />
lastUpdated:
<asp:Label ID="lastUpdated Label" runat="server" Text='<%#
Bind("lastUpdat ed") %>'>
</asp:Label><br />
<asp:LinkButt on ID="link1" runat="server" CommandName="Ne w"
Text="New"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>"
SelectCommand=" SELECT [id], [code], [lastUpdated] FROM [Table1]"
InsertCommand=" Insert into Table1(id,code, lastUpdated)
values(@id,@cod e,@lastUpdated) "
>
<InsertParamete rs>
<asp:Paramete r Name="id" Type="int32" />
<asp:Paramete r Name="code" Type="String"
DefaultValue="d efault code" />
<asp:Paramete r Name="lastUpdat ed" Type="DateTime"
DefaultValue="2 007/12/24" />
</InsertParameter s>
</asp:SqlDataSour ce>

</div>
</form>
</body>
</html>

I think the date parameter's DefaultValue string is parsed using the
current culture of the webform when it's executed, which means this will
depend on the user's browser setting if you're using auto culture for the
webform.

Let me know if this simple test works on your side.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 18 '07 #2
Thanks Walter. I knew it was something simple.

One more question:

How would I (using declarative markup) set the defaultdate to the current
date?

Thanks again,

Ken
Microsoft MVP [ASP.NET]
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:6q******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Ken,

I've done some test and it seems it's working on my side when you use:

<asp:Paramete r Name="lastUpdat ed" Type="DateTime"
DefaultValue="2 007/12/24"
/>
Here's my test steps:

1) Create a SQLExpress database in VS2005, add a table with three fields:
id, code, lastUpdated.

2) Add a FormView and SqlDataSource to use the table:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="i d"
DataSourceID="S qlDataSource1">
<EditItemTempla te>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%#
Eval("id") %>'></asp:Label><br />
code:
<asp:TextBox ID="codeTextBox " runat="server" Text='<%#
Bind("code") %>'>
</asp:TextBox><br />
lastUpdated:
<asp:TextBox ID="lastUpdated TextBox" runat="server"
Text='<%# Bind("lastUpdat ed") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
id:
<asp:TextBox ID="idTextBox" runat="server" Text='<%#
Bind("id") %>'>
</asp:TextBox><br />
code:
<asp:TextBox ID="codeTextBox " runat="server" Text='<%#
Bind("code") %>'>
</asp:TextBox><br />
lastUpdated:
<asp:TextBox ID="lastUpdated TextBox" runat="server"
Text='<%# Bind("lastUpdat ed") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id")
%>'></asp:Label><br />
code:
<asp:Label ID="codeLabel" runat="server" Text='<%#
Bind("code") %>'></asp:Label><br />
lastUpdated:
<asp:Label ID="lastUpdated Label" runat="server" Text='<%#
Bind("lastUpdat ed") %>'>
</asp:Label><br />
<asp:LinkButt on ID="link1" runat="server" CommandName="Ne w"
Text="New"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>"
SelectCommand=" SELECT [id], [code], [lastUpdated] FROM
[Table1]"
InsertCommand=" Insert into Table1(id,code, lastUpdated)
values(@id,@cod e,@lastUpdated) "
>
<InsertParamete rs>
<asp:Paramete r Name="id" Type="int32" />
<asp:Paramete r Name="code" Type="String"
DefaultValue="d efault code" />
<asp:Paramete r Name="lastUpdat ed" Type="DateTime"
DefaultValue="2 007/12/24" />
</InsertParameter s>
</asp:SqlDataSour ce>

</div>
</form>
</body>
</html>

I think the date parameter's DefaultValue string is parsed using the
current culture of the webform when it's executed, which means this will
depend on the user's browser setting if you're using auto culture for the
webform.

Let me know if this simple test works on your side.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 19 '07 #3
Hi Ken,

The InsertParameter s of SqlDataSource is persisted as
"PersistenceMod e(PersistenceMo de.InnerPropert y)", therefore I don't think
we're able to use an expression such as this to get the current datetime
declaratively:

DefaultValue="< %= DateTime.Now.To String() %>"
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1007
by: ayende | last post by:
I've the following scenario, a web page that dispaly a GridView using SqlDataSource define thus: <asp:SqlDataSource ID="BoardTypes" runat="server" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT BoardTypes.BoardTypeId, BoardTypes.BoardTypeName, BoardTypes.BoardTypeDescription, BoardTypes.ValidityEndDate,...
8
5023
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for...
2
1489
by: Jarod | last post by:
Hey I have storedProcedure that takes 1 param. And I have checkBoxList that I want to bind to sqlDataSource. The parameter needed for stored procedure is in gridView.DataKey ( diffrent for every row ). So ... how to connect it. Jarod
3
8944
by: jkayne | last post by:
Can someone offer some insight of why parameters outside of those contained in a SqlDataSource <UpdateParameters> section would show up in a profiler trace? I'm using: <UpdateParameters> <asp:Parameter Name="MerchID" Type="Int32" /> <asp:Parameter Name="Merchant" Type="String" /> <asp:Parameter Name="ModifiedBy" Type="String" />...
1
5632
by: Mike P | last post by:
I'm a little confused as to how the SqlDataSource works with its DeleteParameters. I have a GridView hooked up to my SqlDataSource. Here is my templatefield with my Delete button : <asp:TemplateField HeaderText="Select"> <ItemTemplate> <asp:LinkButton ID="DeleteButton"
1
3541
by: David Lozzi | last post by:
Howdy, ASP.Net 2.0 using VB on SQL 2005 This is a two fold issue. I have a DetailsView control which users can insert or edit items. Editing works great. Insert works great however I need to display the form once the user has entered the information and clicked Add.
1
6118
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the...
1
1798
by: E. Kwong | last post by:
I just want to select records with a certain date field today's date: <asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$ ConnectionStrings:xyz %>" SelectCommand="SELECT * FROM WHERE ? " OnSelected="src1_Selected"> <SelectParameters>
0
1218
by: E. Kwong | last post by:
I just want to select records with a certain date field today's date: <asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$ ConnectionStrings:xyz %>" SelectCommand="SELECT * FROM WHERE ? " OnSelected="src1_Selected"> <SelectParameters>
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.