what is wrong with save code

  • Thread starter Thread starter forum.microsoft.com
  • Start date Start date
F

forum.microsoft.com

inserted record is present only in the dataset/bindingsource but not in the
sql table
same for updated record, changes is only in the dataset or the bindingsource
but not in the actual physical sql table.
If I refill from table I will not find any changes.


Also the primary key name in the inserted record field may get changed to
something like "system.data.row"
protected void saveclient(bool bFastSave)
{
if (bNew)
{
if (clientNameTextBox.Text == "")
{
setStatus("Please enter name of the new client");
return;
}
}

if (!bFastSave)
{ // edit
// omitted detail biz logic for editing
}
CurrencyManager cm =
(CurrencyManager)this.BindingContext[clientBindingSource, "client"];
cm.EndCurrentEdit();
if (bNew)
{
try
{
ClientTmpDataSet.client.AcceptChanges();
}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:" +
ClientTmpDataSet.client.clientNameColumn);
ClientTmpDataSet.client.RejectChanges();
return;
}
clientBindingSource.EndEdit();
this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).Row);
bNew = false;
}
else
{ //not new record - update
try
{
ClientTmpDataSet.client.AcceptChanges();

}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:" +
ClientTmpDataSet.client.clientNameColumn);
return;
}

clientBindingSource.EndEdit();

this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).Row);
};


bindingNavigator1.Enabled = true;
comboBoxclientName.Enabled = true;
setStatus("save done record count=" + cm.Count);
}
 
inserted record is present only in the dataset/bindingsource but not in the
sql table
same for updated record, changes is only in the dataset or the bindingsource
but not in the actual physical sql table.
If I refill from table I will not find any changes.

Also the primary key name in the inserted record field may get changed to
something like "system.data.row"
protected void saveclient(bool bFastSave)
{
if (bNew)
{
if (clientNameTextBox.Text == "")
{
setStatus("Please enter name of the new client");
return;
}
}

if (!bFastSave)
{ // edit
// omitted detail biz logic for editing
}
CurrencyManager cm =
(CurrencyManager)this.BindingContext[clientBindingSource, "client"];
cm.EndCurrentEdit();
if (bNew)
{
try
{
ClientTmpDataSet.client.AcceptChanges();
}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:" +
ClientTmpDataSet.client.clientNameColumn);
ClientTmpDataSet.client.RejectChanges();
return;
}
clientBindingSource.EndEdit();
this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).R-ow);
bNew = false;
}
else
{ //not new record - update
try
{
ClientTmpDataSet.client.AcceptChanges();

}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:" +
ClientTmpDataSet.client.clientNameColumn);
return;
}

clientBindingSource.EndEdit();

this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).R-ow);
};

bindingNavigator1.Enabled = true;
comboBoxclientName.Enabled = true;
setStatus("save done record count=" + cm.Count);
}

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=155835&SiteID=1
might help
 
unfortunately I could not find any other mdf or ldf file for the sql
database during and after execution of the c# form


Furthermore I believe there is actual code error in mine.
why? when I update a record using the code, first time it goes through
without complain, 2nd time, it complained about not able to set the primary
key field clientName. and the textbox for client name may become something
like system.datarow. I did not change that at all. all I changed was client
description column

the form after update can not be closed by alt-F4 key nor the title bars
upper left X click

inserted record is present only in the dataset/bindingsource but not in
the
sql table
same for updated record, changes is only in the dataset or the
bindingsource
but not in the actual physical sql table.
If I refill from table I will not find any changes.

Also the primary key name in the inserted record field may get changed to
something like "system.data.row"
protected void saveclient(bool bFastSave)
{
if (bNew)
{
if (clientNameTextBox.Text == "")
{
setStatus("Please enter name of the new client");
return;
}
}

if (!bFastSave)
{ // edit
// omitted detail biz logic for editing
}
CurrencyManager cm =
(CurrencyManager)this.BindingContext[clientBindingSource, "client"];
cm.EndCurrentEdit();
if (bNew)
{
try
{
ClientTmpDataSet.client.AcceptChanges();
}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:"
+
ClientTmpDataSet.client.clientNameColumn);
ClientTmpDataSet.client.RejectChanges();
return;
}
clientBindingSource.EndEdit();

this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).R-ow);
bNew = false;
}
else
{ //not new record - update
try
{
ClientTmpDataSet.client.AcceptChanges();

}
catch (System.ArgumentException ae)
{
setStatus("Length of client Name is not acceptable:"
+
ClientTmpDataSet.client.clientNameColumn);
return;
}

clientBindingSource.EndEdit();


this.clientTableAdapter.Update(((DataRowView)clientBindingSource.Current).R-ow);
};

bindingNavigator1.Enabled = true;
comboBoxclientName.Enabled = true;
setStatus("save done record count=" + cm.Count);
}

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=155835&SiteID=1
might help
 
Back
Top