LinqDataSource and DateTime?

D

deerchao

I'm trying LinqDataSource, and I've followed every step in scott's
article http://weblogs.asp.net/scottgu/arch...-ui-using-the-asp-linqdatasource-control.aspx
.. And it did work on Northwind, but when trying my own database, it
keeps throwing "System.Data.Linq.ChangeConflictException: Row not
found or changed." when updating data.

Here is the table define:
CREATE TABLE [dbo].[Table1](
[Id] [int] NOT NULL,
[TimeCreated] [datetime] NOT NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

And here is the data:
insert into table1(id, timecreated) values(1, getdate())

And the aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cus.aspx.cs"
Inherits="RfqMan4.Cus" %>

<!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"
DataSourceID="LinqDataSource1" DataKeyNames="id">
<columns>
<asp:commandfield ShowEditButton="True"></
asp:commandfield>
<asp:boundfield DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id"></asp:boundfield>
<asp:boundfield DataField="TimeCreated"
HeaderText="TimeCreated"
SortExpression="TimeCreated"></asp:boundfield>
</columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="RfqMan4.Components.RfqManDataContext"
EnableDelete="True"
EnableInsert="True" EnableUpdate="True"
TableName="Table1s">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>

The problem is when I try to save the update, it throws a
"ChangeConflictException". According to what scott and guys in MSDN
froums, generally this exception occurs when there is a data update
race condition. BUT, I know my data connection has only one client -
the VS testing WebServer, and I open only one browser window, AND the
behind database data is not changed between starting update and saving
-- in fact, using sql server profiler, I realized Linq never send a
select or update sql to see if there is any conflicts before throwing
the exception.

Intresting, if I replace the datetime column TimeCreated with any
other data type like int, nvarchar(50), it works great; And for Orders
table in Northwind which has several datetime columns, it works all
right too.

Any one has any idea about this? Is this a bug you can reproduce or I
did do something wrong? By the way, I'm using Sql Server 2005 + VS2008
beta2.
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top