ANAT2403
asked on
can't get modified record in ADO.net 2.0 with getchanges
I have an application in winforms C# VS2005 ADO.NET
I have a datagridview bound to a dataset.
I fill the dataset with one datatable.
I allow the datagridview to update and change one cell.
I expect that when I ask for GetChanges(DataRowState.Mo dified) on the dataset or on the datatable
to get a true value but I don't.
I try to create a dataview with RowStateFilter = DataViewRowState.ModifiedO riginal - nothing. I get 0.
why can't I get the modified records?
Thankyou
Anat
I have a datagridview bound to a dataset.
I fill the dataset with one datatable.
I allow the datagridview to update and change one cell.
I expect that when I ask for GetChanges(DataRowState.Mo
to get a true value but I don't.
I try to create a dataview with RowStateFilter = DataViewRowState.ModifiedO
why can't I get the modified records?
Thankyou
Anat
ASKER
I am changing the datatable myself in the dataGridView1_CellEndEdit.
s i think u need to DataGridView.EndEdit or move the control away from the datagri view before calling getchanges. i had the same problem and what i did was before calling the Dataset.getchages i took the focus away from the gird by fousing on a button in the form. so that the underlying datasource would get updated.
<datatable myself in the dataGridView1_CellEndEdit>
can u post the code
how are u chaging are u directly changing the datatable ...
can u post the code
how are u chaging are u directly changing the datatable ...
ASKER
this isthe code:
I have a schema of datarable without dataadapter
using System;
using System.Collections.Generic ;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Windows.Forms;
namespace testDSChanges
{
public partial class Form2 : Form
{
DataSet1 CDA;
private string SqlString = ConfigurationManager.Conne ctionStrin gs["testDS Changes.Pr operties.S ettings.Co ntentConne ctionStrin g"].ToStri ng();
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
CDA = new DataSet1();
ManufacturerListFill();
dataGridView1.DataSource = CDA.Manufacturers;
}
private void ManufacturerListFill()
{
{
SqlCommand Cmd;
SqlConnection Conn = new SqlConnection(SqlString);
SqlDataAdapter DA = new SqlDataAdapter();
// Set up select command
Cmd = new SqlCommand("ManufacturerLi stGet", Conn);
Cmd.CommandType = CommandType.StoredProcedur e;
Conn.Open();
SqlDataReader DR = null;
DR = Cmd.ExecuteReader();
DataRow rowReader;
string Name;
while (DR.Read())
{
rowReader = CDA.Manufacturers.NewRow() ;
rowReader["ManufacturerId" ] = DR.GetInt32(0); //read ManufacturerId
Name = DR.GetString(1); //read Name
rowReader["Manufacturer"] = Name;
CDA.Manufacturers.Rows.Add (rowReader );
}
Conn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
DataSet dschanges;
DataView dvchanged;
DataTable dtchange1 = CDA.Manufacturers.GetChang es();
DataTable dtchange2 = CDA.Manufacturers.GetChang es(DataRow State.Modi fied);
}
private void dataGridView1_CellEndEdit( object sender, DataGridViewCellEventArgs e)
{
string ChangedValue = dataGridView1.Rows[e.RowIn dex].Cells [e.ColumnI ndex].Valu e.ToString ();
string keyIDStr = dataGridView1.Rows[e.RowIn dex].Cells [0].Value. ToString() ;
DataRow dr;
dr = CDA.Manufacturers.Rows.Fin d(keyIDStr );
dr.BeginEdit();
dr["Manufacturer"] = ChangedValue;
dr.EndEdit();
}
}
}
I have a schema of datarable without dataadapter
using System;
using System.Collections.Generic
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Windows.Forms;
namespace testDSChanges
{
public partial class Form2 : Form
{
DataSet1 CDA;
private string SqlString = ConfigurationManager.Conne
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
CDA = new DataSet1();
ManufacturerListFill();
dataGridView1.DataSource = CDA.Manufacturers;
}
private void ManufacturerListFill()
{
{
SqlCommand Cmd;
SqlConnection Conn = new SqlConnection(SqlString);
SqlDataAdapter DA = new SqlDataAdapter();
// Set up select command
Cmd = new SqlCommand("ManufacturerLi
Cmd.CommandType = CommandType.StoredProcedur
Conn.Open();
SqlDataReader DR = null;
DR = Cmd.ExecuteReader();
DataRow rowReader;
string Name;
while (DR.Read())
{
rowReader = CDA.Manufacturers.NewRow()
rowReader["ManufacturerId"
Name = DR.GetString(1); //read Name
rowReader["Manufacturer"] = Name;
CDA.Manufacturers.Rows.Add
}
Conn.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
DataSet dschanges;
DataView dvchanged;
DataTable dtchange1 = CDA.Manufacturers.GetChang
DataTable dtchange2 = CDA.Manufacturers.GetChang
}
private void dataGridView1_CellEndEdit(
{
string ChangedValue = dataGridView1.Rows[e.RowIn
string keyIDStr = dataGridView1.Rows[e.RowIn
DataRow dr;
dr = CDA.Manufacturers.Rows.Fin
dr.BeginEdit();
dr["Manufacturer"] = ChangedValue;
dr.EndEdit();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are great!
Everything you wrote is exactly what happend. It is the acceptchanges in the beginning after filling the datatable.
Thankyou very much
Anat
Everything you wrote is exactly what happend. It is the acceptchanges in the beginning after filling the datatable.
Thankyou very much
Anat
Bob