473,699 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Hidden DateTime column value update problem

Hi,

I have a GridView and a SqlDataSource controls on a page. The SqlDataSource
object uses stored procedures to do the CRUD operations. The DataSource has
three columns one of which - "Modified" of type DateTime - is hidden since it
should not be edited by a user. The system handles the update for this
column. So, I have hidden (Visible=false) this column on the grid. In order
to access the value in this field, I have created a template column and
assigned the "Modified" column to it. The Update Stored Procedure does the
cocurrency checks by looking at the value in the Modified column which holds
the last modified datetime. Everything seems to work fine except that the
datetime value that is held in the template column does not equal the
"Modified" column in the table when the stored procedure compares it.
Obviously, when I store the "Modified" column value in the template field's
text property, somehow it looses the information partly. In other words, may
be, it is dropping the milli seconds. How can I make these two values compare
properly. I am pasting the my page code, the table structure and the Update
stored procedure here. Can somebody please help me figure this one out.

Babu.

Table:
CREATE TABLE [dbo].[ProperNames](
[PKId] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ LastName] DEFAULT ('Unknown'),
[Modified] [datetime] NOT NULL CONSTRAINT [DF_ProperNames_ Modified]
DEFAULT (getdate()),
CONSTRAINT [PK_ProperNames] PRIMARY KEY CLUSTERED
(
[PKId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER PROCEDURE [dbo].[ProperNamesUpda te]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@Firs tName,
LastName=@LastN ame,Modified=ge tdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

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

<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:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
DataKeyNames="P KId"
DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowDeleteButto n="True" ShowEditButton= "True" />
<asp:BoundFie ld DataField="PKId " HeaderText="PKI d"
InsertVisible=" False" ReadOnly="True"
SortExpression= "PKId" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir stName"
SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las tName"
SortExpression= "LastName" />
<asp:BoundFie ld DataField="Modi fied" HeaderText="Mod ified"
SortExpression= "Modified"
Visible="False" />
<asp:TemplateFi eld Visible="False" >
<ItemTemplate >
<asp:Label ID="lblModified " runat="server" Text='<%# Eval("Modified" )
%>' />
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataNozzleDe vConnectionStri ng %>"
DeleteCommand=" ProperNamesDele te" DeleteCommandTy pe="StoredProce dure"
InsertCommand=" ProperNamesInse rt"
InsertCommandTy pe="StoredProce dure" SelectCommand=" ProperNamesSele ctAll"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" ProperNamesUpda te" UpdateCommandTy pe="StoredProce dure"
OnUpdating="Sql DataSource1_Upd ating">
<DeleteParamete rs>
<asp:Paramete r Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="Modified" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</form>
</body>
</html>

protected void SqlDataSource1_ Updating(object sender,
SqlDataSourceCo mmandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditI ndex];
DateTime modified =
Convert.ToDateT ime(((Label)gr. FindControl("lb lModified")).Te xt);
e.Command.Param eters["@Modified"].Value = modified;
}
--
BabuMan
Feb 1 '07 #1
4 7245
BabuMan,

Make sure that the column type in your SQL database is DATETIME rather than
SMALLDATETIME.

Is that the case?

--
Regards,
Robson Siqueira
Enterprise Architect
"BabuMan" <Ba*****@discus sions.microsoft .comwrote in message
news:CB******** *************** ***********@mic rosoft.com...
Hi,

I have a GridView and a SqlDataSource controls on a page. The
SqlDataSource
object uses stored procedures to do the CRUD operations. The DataSource
has
three columns one of which - "Modified" of type DateTime - is hidden since
it
should not be edited by a user. The system handles the update for this
column. So, I have hidden (Visible=false) this column on the grid. In
order
to access the value in this field, I have created a template column and
assigned the "Modified" column to it. The Update Stored Procedure does the
cocurrency checks by looking at the value in the Modified column which
holds
the last modified datetime. Everything seems to work fine except that the
datetime value that is held in the template column does not equal the
"Modified" column in the table when the stored procedure compares it.
Obviously, when I store the "Modified" column value in the template
field's
text property, somehow it looses the information partly. In other words,
may
be, it is dropping the milli seconds. How can I make these two values
compare
properly. I am pasting the my page code, the table structure and the
Update
stored procedure here. Can somebody please help me figure this one out.

Babu.

Table:
CREATE TABLE [dbo].[ProperNames](
[PKId] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ LastName] DEFAULT ('Unknown'),
[Modified] [datetime] NOT NULL CONSTRAINT [DF_ProperNames_ Modified]
DEFAULT (getdate()),
CONSTRAINT [PK_ProperNames] PRIMARY KEY CLUSTERED
(
[PKId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER PROCEDURE [dbo].[ProperNamesUpda te]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@Firs tName,
LastName=@LastN ame,Modified=ge tdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

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

<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:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
DataKeyNames="P KId"
DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowDeleteButto n="True" ShowEditButton= "True" />
<asp:BoundFie ld DataField="PKId " HeaderText="PKI d"
InsertVisible=" False" ReadOnly="True"
SortExpression= "PKId" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir stName"
SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las tName"
SortExpression= "LastName" />
<asp:BoundFie ld DataField="Modi fied" HeaderText="Mod ified"
SortExpression= "Modified"
Visible="False" />
<asp:TemplateFi eld Visible="False" >
<ItemTemplate >
<asp:Label ID="lblModified " runat="server" Text='<%# Eval("Modified" )
%>' />
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataNozzleDe vConnectionStri ng %>"
DeleteCommand=" ProperNamesDele te" DeleteCommandTy pe="StoredProce dure"
InsertCommand=" ProperNamesInse rt"
InsertCommandTy pe="StoredProce dure" SelectCommand=" ProperNamesSele ctAll"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" ProperNamesUpda te" UpdateCommandTy pe="StoredProce dure"
OnUpdating="Sql DataSource1_Upd ating">
<DeleteParamete rs>
<asp:Paramete r Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="Modified" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</form>
</body>
</html>

protected void SqlDataSource1_ Updating(object sender,
SqlDataSourceCo mmandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditI ndex];
DateTime modified =
Convert.ToDateT ime(((Label)gr. FindControl("lb lModified")).Te xt);
e.Command.Param eters["@Modified"].Value = modified;
}
--
BabuMan

Feb 1 '07 #2
Thanks for the reply Robson. The column type in the SQL Database table is
datetime (not smalldatetime). I have included the Table structure as sql
script in the post. I hope this helps analyze further.
--
BabuMan
"BabuMan" wrote:
Hi,

I have a GridView and a SqlDataSource controls on a page. The SqlDataSource
object uses stored procedures to do the CRUD operations. The DataSource has
three columns one of which - "Modified" of type DateTime - is hidden since it
should not be edited by a user. The system handles the update for this
column. So, I have hidden (Visible=false) this column on the grid. In order
to access the value in this field, I have created a template column and
assigned the "Modified" column to it. The Update Stored Procedure does the
cocurrency checks by looking at the value in the Modified column which holds
the last modified datetime. Everything seems to work fine except that the
datetime value that is held in the template column does not equal the
"Modified" column in the table when the stored procedure compares it.
Obviously, when I store the "Modified" column value in the template field's
text property, somehow it looses the information partly. In other words, may
be, it is dropping the milli seconds. How can I make these two values compare
properly. I am pasting the my page code, the table structure and the Update
stored procedure here. Can somebody please help me figure this one out.

Babu.

Table:
CREATE TABLE [dbo].[ProperNames](
[PKId] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ LastName] DEFAULT ('Unknown'),
[Modified] [datetime] NOT NULL CONSTRAINT [DF_ProperNames_ Modified]
DEFAULT (getdate()),
CONSTRAINT [PK_ProperNames] PRIMARY KEY CLUSTERED
(
[PKId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER PROCEDURE [dbo].[ProperNamesUpda te]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@Firs tName,
LastName=@LastN ame,Modified=ge tdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

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

<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:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
DataKeyNames="P KId"
DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowDeleteButto n="True" ShowEditButton= "True" />
<asp:BoundFie ld DataField="PKId " HeaderText="PKI d"
InsertVisible=" False" ReadOnly="True"
SortExpression= "PKId" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir stName"
SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las tName"
SortExpression= "LastName" />
<asp:BoundFie ld DataField="Modi fied" HeaderText="Mod ified"
SortExpression= "Modified"
Visible="False" />
<asp:TemplateFi eld Visible="False" >
<ItemTemplate >
<asp:Label ID="lblModified " runat="server" Text='<%# Eval("Modified" )
%>' />
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataNozzleDe vConnectionStri ng %>"
DeleteCommand=" ProperNamesDele te" DeleteCommandTy pe="StoredProce dure"
InsertCommand=" ProperNamesInse rt"
InsertCommandTy pe="StoredProce dure" SelectCommand=" ProperNamesSele ctAll"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" ProperNamesUpda te" UpdateCommandTy pe="StoredProce dure"
OnUpdating="Sql DataSource1_Upd ating">
<DeleteParamete rs>
<asp:Paramete r Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="Modified" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</form>
</body>
</html>

protected void SqlDataSource1_ Updating(object sender,
SqlDataSourceCo mmandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditI ndex];
DateTime modified =
Convert.ToDateT ime(((Label)gr. FindControl("lb lModified")).Te xt);
e.Command.Param eters["@Modified"].Value = modified;
}
--
BabuMan
Feb 1 '07 #3
BabuMan,

Are you not loosing your data when converting the text data to DateTime?

Besides, why don't you receive the parameter in the stored procedure as
datetime instead of varchar? Please remember that there is a implicit cast
here and your problem may be here as well.

--
Regards,
Robson Siqueira
Enterprise Architect
"BabuMan" <Ba*****@discus sions.microsoft .comwrote in message
news:84******** *************** ***********@mic rosoft.com...
Thanks for the reply Robson. The column type in the SQL Database table is
datetime (not smalldatetime). I have included the Table structure as sql
script in the post. I hope this helps analyze further.
--
BabuMan
"BabuMan" wrote:
>Hi,

I have a GridView and a SqlDataSource controls on a page. The
SqlDataSourc e
object uses stored procedures to do the CRUD operations. The DataSource
has
three columns one of which - "Modified" of type DateTime - is hidden
since it
should not be edited by a user. The system handles the update for this
column. So, I have hidden (Visible=false) this column on the grid. In
order
to access the value in this field, I have created a template column and
assigned the "Modified" column to it. The Update Stored Procedure does
the
cocurrency checks by looking at the value in the Modified column which
holds
the last modified datetime. Everything seems to work fine except that
the
datetime value that is held in the template column does not equal the
"Modified" column in the table when the stored procedure compares it.
Obviously, when I store the "Modified" column value in the template
field's
text property, somehow it looses the information partly. In other words,
may
be, it is dropping the milli seconds. How can I make these two values
compare
properly. I am pasting the my page code, the table structure and the
Update
stored procedure here. Can somebody please help me figure this one out.

Babu.

Table:
CREATE TABLE [dbo].[ProperNames](
[PKId] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ LastName] DEFAULT ('Unknown'),
[Modified] [datetime] NOT NULL CONSTRAINT [DF_ProperNames_ Modified]
DEFAULT (getdate()),
CONSTRAINT [PK_ProperNames] PRIMARY KEY CLUSTERED
(
[PKId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER PROCEDURE [dbo].[ProperNamesUpda te]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@Firs tName,
LastName=@Last Name,Modified=g etdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Def ault" %>

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

<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:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
DataKeyNames=" PKId"
DataSourceID=" SqlDataSource1" >
<Columns>
<asp:CommandFi eld ShowDeleteButto n="True" ShowEditButton= "True" />
<asp:BoundFiel d DataField="PKId " HeaderText="PKI d"
InsertVisible= "False" ReadOnly="True"
SortExpression ="PKId" />
<asp:BoundFiel d DataField="Firs tName" HeaderText="Fir stName"
SortExpression ="FirstName" />
<asp:BoundFiel d DataField="Last Name" HeaderText="Las tName"
SortExpression ="LastName" />
<asp:BoundFiel d DataField="Modi fied" HeaderText="Mod ified"
SortExpression ="Modified"
Visible="False " />
<asp:TemplateF ield Visible="False" >
<ItemTemplat e>
<asp:Label ID="lblModified " runat="server" Text='<%# Eval("Modified" )
%>' />
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSo urce ID="SqlDataSour ce1" runat="server"
ConnectionStri ng="<%$ ConnectionStrin gs:DataNozzleDe vConnectionStri ng %>"
DeleteCommand= "ProperNamesDel ete" DeleteCommandTy pe="StoredProce dure"
InsertCommand= "ProperNamesIns ert"
InsertCommandT ype="StoredProc edure" SelectCommand=" ProperNamesSele ctAll"
SelectCommandT ype="StoredProc edure"
UpdateCommand= "ProperNamesUpd ate" UpdateCommandTy pe="StoredProce dure"
OnUpdating="Sq lDataSource1_Up dating">
<DeleteParamet ers>
<asp:Paramet er Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamet ers>
<asp:Paramet er Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramet er Name="FirstName " Type="String" />
<asp:Paramet er Name="LastName" Type="String" />
<asp:Paramet er Name="Modified" Type="String" />
</UpdateParameter s>
<InsertParamet ers>
<asp:Paramet er Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramet er Name="FirstName " Type="String" />
<asp:Paramet er Name="LastName" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</form>
</body>
</html>

protected void SqlDataSource1_ Updating(object sender,
SqlDataSourceC ommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditI ndex];
DateTime modified =
Convert.ToDate Time(((Label)gr .FindControl("l blModified")).T ext);
e.Command.Para meters["@Modified"].Value = modified;
}
--
BabuMan

Feb 1 '07 #4
Thanks Again. Yes. That is exactly my problem. I am loosing the data
partially when recieved by the stored procedure. But I have no other choice
since the date is stored as text when it is initially retrieved. That again
is compulsion and not a choice.

Anyway, I think I am very close to finding an efficient and fairly "best
practice" solution for this problem. But thank you very much for your
effort. I really appreciate it.
--
BabuMan
"Robson Siqueira" wrote:
BabuMan,

Are you not loosing your data when converting the text data to DateTime?

Besides, why don't you receive the parameter in the stored procedure as
datetime instead of varchar? Please remember that there is a implicit cast
here and your problem may be here as well.

--
Regards,
Robson Siqueira
Enterprise Architect
"BabuMan" <Ba*****@discus sions.microsoft .comwrote in message
news:84******** *************** ***********@mic rosoft.com...
Thanks for the reply Robson. The column type in the SQL Database table is
datetime (not smalldatetime). I have included the Table structure as sql
script in the post. I hope this helps analyze further.
--
BabuMan
"BabuMan" wrote:
Hi,

I have a GridView and a SqlDataSource controls on a page. The
SqlDataSource
object uses stored procedures to do the CRUD operations. The DataSource
has
three columns one of which - "Modified" of type DateTime - is hidden
since it
should not be edited by a user. The system handles the update for this
column. So, I have hidden (Visible=false) this column on the grid. In
order
to access the value in this field, I have created a template column and
assigned the "Modified" column to it. The Update Stored Procedure does
the
cocurrency checks by looking at the value in the Modified column which
holds
the last modified datetime. Everything seems to work fine except that
the
datetime value that is held in the template column does not equal the
"Modified" column in the table when the stored procedure compares it.
Obviously, when I store the "Modified" column value in the template
field's
text property, somehow it looses the information partly. In other words,
may
be, it is dropping the milli seconds. How can I make these two values
compare
properly. I am pasting the my page code, the table structure and the
Update
stored procedure here. Can somebody please help me figure this one out.

Babu.

Table:
CREATE TABLE [dbo].[ProperNames](
[PKId] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_ LastName] DEFAULT ('Unknown'),
[Modified] [datetime] NOT NULL CONSTRAINT [DF_ProperNames_ Modified]
DEFAULT (getdate()),
CONSTRAINT [PK_ProperNames] PRIMARY KEY CLUSTERED
(
[PKId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

ALTER PROCEDURE [dbo].[ProperNamesUpda te]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@Firs tName,
LastName=@LastN ame,Modified=ge tdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Defau lt.aspx.cs"
Inherits="_Defa ult" %>

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

<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:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"
DataKeyNames="P KId"
DataSourceID="S qlDataSource1">
<Columns>
<asp:CommandFie ld ShowDeleteButto n="True" ShowEditButton= "True" />
<asp:BoundFie ld DataField="PKId " HeaderText="PKI d"
InsertVisible=" False" ReadOnly="True"
SortExpression= "PKId" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir stName"
SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las tName"
SortExpression= "LastName" />
<asp:BoundFie ld DataField="Modi fied" HeaderText="Mod ified"
SortExpression= "Modified"
Visible="False" />
<asp:TemplateFi eld Visible="False" >
<ItemTemplate >
<asp:Label ID="lblModified " runat="server" Text='<%# Eval("Modified" )
%>' />
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataNozzleDe vConnectionStri ng %>"
DeleteCommand=" ProperNamesDele te" DeleteCommandTy pe="StoredProce dure"
InsertCommand=" ProperNamesInse rt"
InsertCommandTy pe="StoredProce dure" SelectCommand=" ProperNamesSele ctAll"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" ProperNamesUpda te" UpdateCommandTy pe="StoredProce dure"
OnUpdating="Sql DataSource1_Upd ating">
<DeleteParamete rs>
<asp:Paramete r Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="Modified" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Direction="Inpu tOutput" Name="PKId" Type="Decimal" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</form>
</body>
</html>

protected void SqlDataSource1_ Updating(object sender,
SqlDataSourceCo mmandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditI ndex];
DateTime modified =
Convert.ToDateT ime(((Label)gr. FindControl("lb lModified")).Te xt);
e.Command.Param eters["@Modified"].Value = modified;
}
--
BabuMan


Feb 2 '07 #5

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

Similar topics

1
2996
by: scj | last post by:
Hi all, I need to determine the exact type of DateTime column(*) in an Access 97 database. I'm able to do this with an Access 2 database. With ADO.Net and VB.Net (**), I do something like this : Dim oDT As New DataTable() Dim oCnx As OleDbConnection
31
2439
by: Lag | last post by:
Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I changed them here for securiy reasons :) ) <?php /*---CONNECT TO DATABASE---*/
2
10447
by: Godzilla | last post by:
Dear all, I have a challenge in hand and am not too sure how to accomplish this using stored procedure. I have a table containing about 3 fields, but I need to reorder/renumber a field value every time there is an insert or delete on the table. Below is the table structure: tableID customerID pageID ===== ======== ====== 0 1 0
5
51644
by: GG | last post by:
I am trying to add a nullable datetime column to a datatable fails. I am getting exception DataSet does not support System.Nullable<>. None of these works dtSearchFromData.Columns.Add( new DataColumn( "StartDate", typeof( DateTime? ) ) ); dtSearchFromData.Columns.Add( new DataColumn( "EndDate", typeof( System.Nullable<DateTime>) ) ); Any ideas?
0
1105
by: Shea Martin | last post by:
I have DataGridView with a column of type DateTime. I would like the editing to be with a MonthCalendar instead of text mode. What is the standard method of doing this? ~S
2
5431
by: jdrake | last post by:
Hi, I have a large table with a 'datetime' column that has date and time values in it. The data is in this format: 2007-10-02 09:54:00.000 The table is called 'profile' and the column 'msgdate' I want to return only rows that match a specific date. So far I have
2
2880
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of various module that I found it useful. Here is the 1st problem I encounter: I had a function to edit a event row form the database which is fine with me, than I pass on the code to a function that save(update) the data to the database.
3
1510
by: hauschild | last post by:
Guys, I am looping thru a dataset and need to update rows' columns based on the ColumnName value. I get this far but I'm unsure of how to update that actual columns value with the new value. Code follows: string sDate = (Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToString()); string BritishDate; string USDate; if (sDate != "MM/dd/yyyy")
11
6062
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
0
8704
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4390
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.