V
Vladimir O¾ura
I am building a pocket pc application that requires a datagrid. I am
inserting a new row this way:
private void mInsert_Click(object sender, System.EventArgs e)
{
try
{
DataRow dr = this.ldb.DohvatiDataSet.Tables[tableName].NewRow();
dr.BeginEdit();
for(int i = 0; i <
this.ldb.DohvatiDataSet.Tables[tableName].Columns.Count; i++)
if(!this.ldb.DohvatiDataSet.Tables[tableName].Columns.ReadOnly)
dr =
this.ldb.DohvatiDataSet.Tables[tableName].Columns.DefaultValue;
if(!this.cbImena.SelectedItem.ToString().Equals("<SVE OSOBE>"))
dr["Osoba"] = this.cbImena.SelectedItem.ToString();
if(!this.cbProjekt.SelectedItem.ToString().Equals("<SVE PROJEKTE>"))
dr["KratProjekt"] = this.cbProjekt.SelectedItem.ToString();
if(!this.cbVrstePosla.SelectedItem.ToString().Equals("<SVE VRSTE
POSLA>"))
dr["KratPosao"] = this.cbVrstePosla.SelectedItem.ToString();
if(this.checkBox1.Checked)
dr["DatPosao"] = this.dtp.Value.ToString();
dr.EndEdit();
this.ldb.DohvatiDataSet.Tables[tableName].Rows.Add(dr);
this.mSave_Click(this, System.EventArgs.Empty); // defined at the bottom
of this method
this.ldb.DohvatiDataSet.Tables[tableName].DefaultView.Sort = "";
this.dataGrid1.CurrentRowIndex =
this.ldb.DohvatiDataSet.Tables[tableName].DefaultView.Count - 1;
this.dataGrid1.ScrollToLeft();
}
catch(System.Data.DBConcurrencyException dbce)
{
MessageBox.Show(dbce.Message.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
private void mSave_Click(object sender, System.EventArgs e)
{
try
{
Cursor.Current = Cursors.WaitCursor;
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.Deleted));
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.ModifiedCurrent));
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.Added));
this.ldb.DohvatiDataSet.AcceptChanges();
this.dataGrid1.Focus();
Cursor.Current = Cursors.Default;
this.UpdateAgreg();
}
catch(System.Data.DBConcurrencyException dbce)
{
if(Cursor.Current == Cursors.WaitCursor) Cursor.Current =
Cursors.Default;
MessageBox.Show(dbce.Message.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
I only get a concurrency violation when I insert a new row and change data
in it, that save it. If no new rows are inserted I don't get a concurrency
violation. Please help!
Vladimir O¾ura!
inserting a new row this way:
private void mInsert_Click(object sender, System.EventArgs e)
{
try
{
DataRow dr = this.ldb.DohvatiDataSet.Tables[tableName].NewRow();
dr.BeginEdit();
for(int i = 0; i <
this.ldb.DohvatiDataSet.Tables[tableName].Columns.Count; i++)
if(!this.ldb.DohvatiDataSet.Tables[tableName].Columns.ReadOnly)
dr =
this.ldb.DohvatiDataSet.Tables[tableName].Columns.DefaultValue;
if(!this.cbImena.SelectedItem.ToString().Equals("<SVE OSOBE>"))
dr["Osoba"] = this.cbImena.SelectedItem.ToString();
if(!this.cbProjekt.SelectedItem.ToString().Equals("<SVE PROJEKTE>"))
dr["KratProjekt"] = this.cbProjekt.SelectedItem.ToString();
if(!this.cbVrstePosla.SelectedItem.ToString().Equals("<SVE VRSTE
POSLA>"))
dr["KratPosao"] = this.cbVrstePosla.SelectedItem.ToString();
if(this.checkBox1.Checked)
dr["DatPosao"] = this.dtp.Value.ToString();
dr.EndEdit();
this.ldb.DohvatiDataSet.Tables[tableName].Rows.Add(dr);
this.mSave_Click(this, System.EventArgs.Empty); // defined at the bottom
of this method
this.ldb.DohvatiDataSet.Tables[tableName].DefaultView.Sort = "";
this.dataGrid1.CurrentRowIndex =
this.ldb.DohvatiDataSet.Tables[tableName].DefaultView.Count - 1;
this.dataGrid1.ScrollToLeft();
}
catch(System.Data.DBConcurrencyException dbce)
{
MessageBox.Show(dbce.Message.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
private void mSave_Click(object sender, System.EventArgs e)
{
try
{
Cursor.Current = Cursors.WaitCursor;
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.Deleted));
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.ModifiedCurrent));
((SqlCeDataAdapter)(this.ldb.GetAdapterList[this.ldb.GetTableIndex(tableName
)])).Update(this.ldb.DohvatiDataSet.Tables[tableName].Select(null, null,
DataViewRowState.Added));
this.ldb.DohvatiDataSet.AcceptChanges();
this.dataGrid1.Focus();
Cursor.Current = Cursors.Default;
this.UpdateAgreg();
}
catch(System.Data.DBConcurrencyException dbce)
{
if(Cursor.Current == Cursors.WaitCursor) Cursor.Current =
Cursors.Default;
MessageBox.Show(dbce.Message.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
I only get a concurrency violation when I insert a new row and change data
in it, that save it. If no new rows are inserted I don't get a concurrency
violation. Please help!
Vladimir O¾ura!