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.Modified) 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.ModifiedOriginal - nothing. I get 0.
why can't I get the modified records?
Thankyou
Anat
ANAT2403Asked:
Who is Participating?
 
Gautham JanardhanConnect With a Mentor Commented:
u are not callig accept changes any where rt ? from the code u posted i dont find it anywhere ...
and also afer this

 dr = CDA.Manufacturers.Rows.Find(keyIDStr);
            dr.BeginEdit();
            dr["Manufacturer"] = ChangedValue;
            dr.EndEdit();

can u do MessageBox.Show(dr.RowState.ToString());

i think ur row dr is not in Modified State
since u r doing this

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);
                }


the row state will be Added
and not modified

do a CDA.AcceptChanges(); in
ManufacturerListFill after adding  rows

0
 
Bob LearnedCommented:
You can try to call DataGridView.EndEdit, and see if that helps.

Bob
0
 
ANAT2403Author Commented:
I am changing the datatable myself in the dataGridView1_CellEndEdit.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Gautham JanardhanCommented:
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.
0
 
Gautham JanardhanCommented:
<datatable myself in the dataGridView1_CellEndEdit>

can u post the code

how are u chaging are u directly changing the datatable ...
0
 
ANAT2403Author Commented:
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.ConnectionStrings["testDSChanges.Properties.Settings.ContentConnectionString"].ToString();
        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("ManufacturerListGet", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;

                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.GetChanges();
             DataTable dtchange2 = CDA.Manufacturers.GetChanges(DataRowState.Modified);


        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string ChangedValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            string keyIDStr = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            DataRow dr;
            dr = CDA.Manufacturers.Rows.Find(keyIDStr);
            dr.BeginEdit();
            dr["Manufacturer"] = ChangedValue;
            dr.EndEdit();
        }

 
    }
}
0
 
ANAT2403Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.