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 4 7201
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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. ...
|
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...
|
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |