No update happening

  • Thread starter Thread starter David
  • Start date Start date
D

David

I am using SQL Server 2005. I have a form with a grid on it. I have this
code in place:

String strFilter = String.Format("Line={0} AND
Time='{1:D2}/{2:D2}/{3:D4} {4:D2}:{5:D2}'",
m_cd.m_iLine,
m_cd.m_dt.Month, m_cd.m_dt.Day,
m_cd.m_dt.Year,
m_cd.m_dt.Hour, m_cd.m_dt.Minute);

DataRow[] rows =
callerIDTemplateDataSet.Callers.Select(strFilter);
if (rows.Length == 0)
callerIDTemplateDataSet.Callers.AddCallersRow(m_cd.m_iLine,
m_cd.m_strName, m_cd.m_strPhone, m_cd.m_dt, m_cd.m_iDuration, m_cd.m_iRings,
strFirstName, strLastName, strAddress, strCity, strState, strZip, "",
m_cd.m_strIO == "I");
else if (rows.Length == 1)
{
DataRow row = rows[0];
row.BeginEdit();
row["Duration"] = m_cd.m_iDuration;
row["Rings"] = m_cd.m_iRings;
row.AcceptChanges();
}
this.callersTableAdapter.Update(callerIDTemplateDataSet.Callers);

A new row is correctly added to the database. The row shows up in the grid
and it is persisted. However, if row.Length is 1 and update is needed. The
grid shows the update but the data is not persisted to the database. Does
anyone know why this would be? The callerIDTemplateDataSet and
callersTableAdapter were created simply by dropping the grid onto the form.
 
This is a classic.
Instead of AcceptChanges you should call EndEdit();
The former signals that rows isn't modified...
 
Changing the code to use EndEdit results in the following exception being
thrown:

Concurrency violation: the UpdateCommand affected 0 of the expected 1
records.

So, that is not the solution.

Miha Markic said:
This is a classic.
Instead of AcceptChanges you should call EndEdit();
The former signals that rows isn't modified...
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

David said:
I am using SQL Server 2005. I have a form with a grid on it. I have this
code in place:

String strFilter = String.Format("Line={0} AND
Time='{1:D2}/{2:D2}/{3:D4} {4:D2}:{5:D2}'",
m_cd.m_iLine,
m_cd.m_dt.Month, m_cd.m_dt.Day,
m_cd.m_dt.Year,
m_cd.m_dt.Hour, m_cd.m_dt.Minute);

DataRow[] rows =
callerIDTemplateDataSet.Callers.Select(strFilter);
if (rows.Length == 0)

callerIDTemplateDataSet.Callers.AddCallersRow(m_cd.m_iLine,
m_cd.m_strName, m_cd.m_strPhone, m_cd.m_dt, m_cd.m_iDuration,
m_cd.m_iRings, strFirstName, strLastName, strAddress, strCity, strState,
strZip, "", m_cd.m_strIO == "I");
else if (rows.Length == 1)
{
DataRow row = rows[0];
row.BeginEdit();
row["Duration"] = m_cd.m_iDuration;
row["Rings"] = m_cd.m_iRings;
row.AcceptChanges();
}

this.callersTableAdapter.Update(callerIDTemplateDataSet.Callers);

A new row is correctly added to the database. The row shows up in the
grid and it is persisted. However, if row.Length is 1 and update is
needed. The grid shows the update but the data is not persisted to the
database. Does anyone know why this would be? The callerIDTemplateDataSet
and callersTableAdapter were created simply by dropping the grid onto the
form.
 
Changing the code to use EndEdit results in the following exception being
thrown:

Concurrency violation: the UpdateCommand affected 0 of the expected 1
records.

So, that is not the solution.

Miha Markic said:
This is a classic.
Instead of AcceptChanges you should call EndEdit();
The former signals that rows isn't modified...
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

David said:
I am using SQL Server 2005. I have a form with a grid on it. I have this
code in place:

String strFilter = String.Format("Line={0} AND
Time='{1:D2}/{2:D2}/{3:D4} {4:D2}:{5:D2}'",
m_cd.m_iLine,
m_cd.m_dt.Month, m_cd.m_dt.Day,
m_cd.m_dt.Year,
m_cd.m_dt.Hour, m_cd.m_dt.Minute);

DataRow[] rows =
callerIDTemplateDataSet.Callers.Select(strFilter);
if (rows.Length == 0)

callerIDTemplateDataSet.Callers.AddCallersRow(m_cd.m_iLine,
m_cd.m_strName, m_cd.m_strPhone, m_cd.m_dt, m_cd.m_iDuration,
m_cd.m_iRings, strFirstName, strLastName, strAddress, strCity, strState,
strZip, "", m_cd.m_strIO == "I");
else if (rows.Length == 1)
{
DataRow row = rows[0];
row.BeginEdit();
row["Duration"] = m_cd.m_iDuration;
row["Rings"] = m_cd.m_iRings;
row.AcceptChanges();
}

this.callersTableAdapter.Update(callerIDTemplateDataSet.Callers);

A new row is correctly added to the database. The row shows up in the
grid and it is persisted. However, if row.Length is 1 and update is
needed. The grid shows the update but the data is not persisted to the
database. Does anyone know why this would be? The callerIDTemplateDataSet
and callersTableAdapter were created simply by dropping the grid onto the
form.
 
David said:
Changing the code to use EndEdit results in the following exception being
thrown:

Concurrency violation: the UpdateCommand affected 0 of the expected 1
records.

So, that is not the solution.

On the contrary, that is the solution for your first problem. Now you are
bumping to your second problem - update command not being correct.
Check how it is coded.
 
The update command was created by the IDE. I did not manually change it. It
should be correct, right?
 
this._adapter.UpdateCommand.CommandText = @"UPDATE [Callers] SET
[Line] = ?, [Name] = ?, [Number] = ?, [Time] = ?, [Duration] = ?, [Rings] =
?, [FirstName] = ?, [LastName] = ?, [Address] = ?, [City] = ?, [State] = ?,
[Zip] = ?, [MapUrl] = ?, [Incoming] = ? WHERE (([ID] = ?) AND ((? = 1 AND
[Line] IS NULL) OR ([Line] = ?)) AND ((? = 1 AND [Name] IS NULL) OR ([Name]
= ?)) AND ((? = 1 AND [Number] IS NULL) OR ([Number] = ?)) AND ((? = 1 AND
[Time] IS NULL) OR ([Time] = ?)) AND ((? = 1 AND [Duration] IS NULL) OR
([Duration] = ?)) AND ((? = 1 AND [Rings] IS NULL) OR ([Rings] = ?)) AND ((?
= 1 AND [Zip] IS NULL) OR ([Zip] = ?)) AND ([Incoming] = ?))";

Nothing magical about that I think.

Miha Markic said:
Not necessarily - check it out.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

David said:
The update command was created by the IDE. I did not manually change it.
It should be correct, right?
 
David,

The last entry in the following thread may apply to your situation:

http://www.thescripts.com/forum/thread433337.html

Kerry Moorman


David said:
this._adapter.UpdateCommand.CommandText = @"UPDATE [Callers] SET
[Line] = ?, [Name] = ?, [Number] = ?, [Time] = ?, [Duration] = ?, [Rings] =
?, [FirstName] = ?, [LastName] = ?, [Address] = ?, [City] = ?, [State] = ?,
[Zip] = ?, [MapUrl] = ?, [Incoming] = ? WHERE (([ID] = ?) AND ((? = 1 AND
[Line] IS NULL) OR ([Line] = ?)) AND ((? = 1 AND [Name] IS NULL) OR ([Name]
= ?)) AND ((? = 1 AND [Number] IS NULL) OR ([Number] = ?)) AND ((? = 1 AND
[Time] IS NULL) OR ([Time] = ?)) AND ((? = 1 AND [Duration] IS NULL) OR
([Duration] = ?)) AND ((? = 1 AND [Rings] IS NULL) OR ([Rings] = ?)) AND ((?
= 1 AND [Zip] IS NULL) OR ([Zip] = ?)) AND ([Incoming] = ?))";

Nothing magical about that I think.

Miha Markic said:
Not necessarily - check it out.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

David said:
The update command was created by the IDE. I did not manually change it.
It should be correct, right?

"Miha Markic" <miha at rthand com> wrote in message
Changing the code to use EndEdit results in the following exception
being thrown:

Concurrency violation: the UpdateCommand affected 0 of the expected 1
records.

So, that is not the solution.

On the contrary, that is the solution for your first problem. Now you
are bumping to your second problem - update command not being correct.
Check how it is coded.
 
I have two DateTime fields (Time and Duration) and they are of type
DateTime, not Date.

Kerry Moorman said:
David,

The last entry in the following thread may apply to your situation:

http://www.thescripts.com/forum/thread433337.html

Kerry Moorman


David said:
this._adapter.UpdateCommand.CommandText = @"UPDATE [Callers]
SET
[Line] = ?, [Name] = ?, [Number] = ?, [Time] = ?, [Duration] = ?, [Rings]
=
?, [FirstName] = ?, [LastName] = ?, [Address] = ?, [City] = ?, [State] =
?,
[Zip] = ?, [MapUrl] = ?, [Incoming] = ? WHERE (([ID] = ?) AND ((? = 1 AND
[Line] IS NULL) OR ([Line] = ?)) AND ((? = 1 AND [Name] IS NULL) OR
([Name]
= ?)) AND ((? = 1 AND [Number] IS NULL) OR ([Number] = ?)) AND ((? = 1
AND
[Time] IS NULL) OR ([Time] = ?)) AND ((? = 1 AND [Duration] IS NULL) OR
([Duration] = ?)) AND ((? = 1 AND [Rings] IS NULL) OR ([Rings] = ?)) AND
((?
= 1 AND [Zip] IS NULL) OR ([Zip] = ?)) AND ([Incoming] = ?))";

Nothing magical about that I think.

Miha Markic said:
Not necessarily - check it out.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

The update command was created by the IDE. I did not manually change
it.
It should be correct, right?

"Miha Markic" <miha at rthand com> wrote in message
Changing the code to use EndEdit results in the following exception
being thrown:

Concurrency violation: the UpdateCommand affected 0 of the expected
1
records.

So, that is not the solution.

On the contrary, that is the solution for your first problem. Now you
are bumping to your second problem - update command not being
correct.
Check how it is coded.
 
Back
Top