473,221 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

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_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_General_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].[ProperNamesUpdate]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@FirstName,
LastName=@LastName,Modified=getdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="PKId" HeaderText="PKId"
InsertVisible="False" ReadOnly="True"
SortExpression="PKId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Modified" HeaderText="Modified"
SortExpression="Modified"
Visible="False" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblModified" runat="server" Text='<%# Eval("Modified")
%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleDevConnectionString %>"
DeleteCommand="ProperNamesDelete" DeleteCommandType="StoredProcedure"
InsertCommand="ProperNamesInsert"
InsertCommandType="StoredProcedure" SelectCommand="ProperNamesSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="ProperNamesUpdate" UpdateCommandType="StoredProcedure"
OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Modified" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditIndex];
DateTime modified =
Convert.ToDateTime(((Label)gr.FindControl("lblModi fied")).Text);
e.Command.Parameters["@Modified"].Value = modified;
}
--
BabuMan
Feb 1 '07 #1
4 7196
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*****@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.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_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_General_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].[ProperNamesUpdate]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@FirstName,
LastName=@LastName,Modified=getdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="PKId" HeaderText="PKId"
InsertVisible="False" ReadOnly="True"
SortExpression="PKId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Modified" HeaderText="Modified"
SortExpression="Modified"
Visible="False" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblModified" runat="server" Text='<%# Eval("Modified")
%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleDevConnectionString %>"
DeleteCommand="ProperNamesDelete" DeleteCommandType="StoredProcedure"
InsertCommand="ProperNamesInsert"
InsertCommandType="StoredProcedure" SelectCommand="ProperNamesSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="ProperNamesUpdate" UpdateCommandType="StoredProcedure"
OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Modified" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditIndex];
DateTime modified =
Convert.ToDateTime(((Label)gr.FindControl("lblModi fied")).Text);
e.Command.Parameters["@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_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_General_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].[ProperNamesUpdate]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@FirstName,
LastName=@LastName,Modified=getdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="PKId" HeaderText="PKId"
InsertVisible="False" ReadOnly="True"
SortExpression="PKId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Modified" HeaderText="Modified"
SortExpression="Modified"
Visible="False" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblModified" runat="server" Text='<%# Eval("Modified")
%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleDevConnectionString %>"
DeleteCommand="ProperNamesDelete" DeleteCommandType="StoredProcedure"
InsertCommand="ProperNamesInsert"
InsertCommandType="StoredProcedure" SelectCommand="ProperNamesSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="ProperNamesUpdate" UpdateCommandType="StoredProcedure"
OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Modified" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditIndex];
DateTime modified =
Convert.ToDateTime(((Label)gr.FindControl("lblModi fied")).Text);
e.Command.Parameters["@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*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.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_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_General_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].[ProperNamesUpdate]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@FirstName,
LastName=@LastName,Modified=getdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="PKId" HeaderText="PKId"
InsertVisible="False" ReadOnly="True"
SortExpression="PKId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Modified" HeaderText="Modified"
SortExpression="Modified"
Visible="False" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblModified" runat="server" Text='<%# Eval("Modified")
%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleDevConnectionString %>"
DeleteCommand="ProperNamesDelete" DeleteCommandType="StoredProcedure"
InsertCommand="ProperNamesInsert"
InsertCommandType="StoredProcedure" SelectCommand="ProperNamesSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="ProperNamesUpdate" UpdateCommandType="StoredProcedure"
OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Modified" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditIndex];
DateTime modified =
Convert.ToDateTime(((Label)gr.FindControl("lblMod ified")).Text);
e.Command.Parameters["@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*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.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_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_ProperNames_FirstName] DEFAULT ('Unknown'),
[LastName] [varchar](50) COLLATE SQL_Latin1_General_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].[ProperNamesUpdate]
(
@PKId numeric,
@FirstName [varchar](50),
@LastName [varchar](50),
@Modified [varchar](50)
)
AS
UPDATE ProperNames SET FirstName=@FirstName,
LastName=@LastName,Modified=getdate()
WHERE PKId = @PKId and modified = @Modified

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="PKId" HeaderText="PKId"
InsertVisible="False" ReadOnly="True"
SortExpression="PKId" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Modified" HeaderText="Modified"
SortExpression="Modified"
Visible="False" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblModified" runat="server" Text='<%# Eval("Modified")
%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleDevConnectionString %>"
DeleteCommand="ProperNamesDelete" DeleteCommandType="StoredProcedure"
InsertCommand="ProperNamesInsert"
InsertCommandType="StoredProcedure" SelectCommand="ProperNamesSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="ProperNamesUpdate" UpdateCommandType="StoredProcedure"
OnUpdating="SqlDataSource1_Updating">
<DeleteParameters>
<asp:Parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Modified" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Direction="InputOutput" Name="PKId" Type="Decimal" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

protected void SqlDataSource1_Updating(object sender,
SqlDataSourceCommandEventArgs e)
{
GridViewRow gr = GridView1.Rows[GridView1.EditIndex];
DateTime modified =
Convert.ToDateTime(((Label)gr.FindControl("lblModi fied")).Text);
e.Command.Parameters["@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
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...
31
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...
2
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...
5
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...
0
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
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...
2
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...
3
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. ...
11
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.