Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
drey
Starting Member
10 Posts |
Posted - 2004-08-10 : 12:32:23
|
I have a concurrency problem when updating with c#.the fill works fine, but when i update i have a concurrency exception, even though, i am working in my own database and nobody else have is in there.does someone knows how can i fix it?this is my SQL:StringBuilder sql = new StringBuilder();// sql.Append("select datename(\"dw\", t.wdate) as dow, ");// sql.Append("t.wdate, t.wtime, t.wotime, t.projectcode, t.timecardid, p.name "); sql.Append("select t.* "); sql.Append("from timecard t "); sql.Append("left outer join project p on t.projectcode = p.projectcode "); sql.Append("inner join person e on e.personid = t.personid "); sql.AppendFormat("where e.username = '{0}' ", loginName); sql.AppendFormat("and wdate between '{0}' ", startDate.ToShortDateString()); sql.AppendFormat("and '{0}' ", endDate.ToShortDateString()); sql.Append("order by wdate");this is my fill:da.Fill(dtTime);da.MissingSchemaAction = MissingSchemaAction.AddWithKey;this is my update:da.Update(dt); |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-08-10 : 12:47:26
|
What happens when you run the query in Query Analyzer?Tara |
 |
|
drey
Starting Member
10 Posts |
Posted - 2004-08-10 : 12:51:13
|
It works fine. the update statement taken out of the rowupdating event:update timecard set projectcode = 'EA013', wdate = '2004-01-01', wtime = 5, wotime= 0 where timecardid = '264810' |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-10 : 13:27:34
|
i had a problem like that because i used original and current value checking in my update sql. maybe thats what you have???show us the update statement.Go with the flow & have fun! Else fight the flow :) |
 |
|
drey
Starting Member
10 Posts |
Posted - 2004-08-10 : 14:17:05
|
this is my update:updCmd = GetUpdateCommand(); updCmd.Parameters.Add(upddate); updCmd.Parameters.Add(updotime); updCmd.Parameters.Add(updtime); updCmd.Parameters.Add(updprojectcode); updCmd.Parameters.Add(updtimecardid); updCmd.UpdatedRowSource = UpdateRowSource.None; da.UpdateCommand = updCmd;private SqlCommand GetUpdateCommand() { //Update SQL StringBuilder sql = new StringBuilder(); sql.Append("update timecard set "); sql.AppendFormat("projectcode = '{0}', ", @projectcode); sql.AppendFormat("wdate = '{0}', ", @wdate); sql.AppendFormat("wtime = {0}, ", @wtime); sql.AppendFormat("wotime= {0} ", @wotime); sql.AppendFormat("where timecardid = {0}", @timecardid); return new SqlCommand(sql.ToString(),conn); } |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-11 : 05:06:50
|
the only thing that looks strange to me is updCmd.Parameters.Add(upddate);...how do you know to which parameter the value belongs to??shouldn't it be likeupdCmd.Parameters.Add("@wdate", upddate);...the update itself looks ok to me, so i guess you need to debug the data itselftry setting the updCmd.UpdatedRowSource = UpdateRowSource.BothGo with the flow & have fun! Else fight the flow :) |
 |
|
|
|
|
|
|