Home > DeveloperSection > Forums > Unable to add new entry in datatable c#
C G E Mannerheim
C G E Mannerheim

Total Post:29

Points:203
Posted on    June-19-2013 2:55 AM

 ADO.Net ADO.Net 
Ratings:


 1 Reply(s)
 1079  View(s)
Rate this:
Hi Expert,

i'm trying to add a new row to my datatable.

I've no error while running this code but nothing happened in my table.

Here's my code :

        string table = "`DONNEE ENTRANT`";
        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * From " + table, _conn);
        OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(adapter);

        DataTable dataTable = new DataTable(table);
        adapter.Fill(dataTable);
        DataRow row = dataTable.NewRow();

        row["CODE LIAISON"] = "TEST";

        dataTable.Rows.Add(row);
        dataTable.AcceptChanges();

        adapter.Update(dataTable);

Any idea what i'm doing wrong (in this way, I know that we can run command with oleDb but really don't like this way ...).

Thanks


Dev Patel

Total Post:26

Points:182
Posted on    June-19-2013 8:22 AM

Hi Expert,

So remove this line:

dataTable.AcceptChanges();

because that's changing the RowState to Unchanged and you need it left at Added. Further, you need to make sure that your adapter has an InsertStatement defined so it can use it.

Thanks in advance. 

Don't want to miss updates? Please click the below button!

Follow MindStick