C# - Adding a new record issue when using DataTable

EFileTahi-A

Well-known member
Joined
Aug 8, 2004
Messages
539
Location
Portugal / Barreiro
In my Access database there are predefined values for the new records. If I use "INSERT INTO" keyword the these predefined values will be applyed, but, when I add a new row to my DataTable and give it the order to update, none of these predefined values are put in the new row / record, they all become NULL...

Can I force it to use the predefined values when adding a row to a DataTable and saving it (DataTable.Update) to the database?
 
Well there is no Update() method on the DataTable object (which is what you said you were doing). I assumed you were using a DataAdapter to write the changes back to your database in which case you need to have the InsertCommand, UpdateCommand, and/or DeleteCommand set appropriately so it knows how to properly write your changes back. Your help files have plenty of documentation and samples as to how this should be done, there is even a wizard to create a DataAdapter that will build the commands for you.
 
Optikal said:
Well there is no Update() method on the DataTable object (which is what you said you were doing). I assumed you were using a DataAdapter to write the changes back to your database in which case you need to have the InsertCommand, UpdateCommand, and/or DeleteCommand set appropriately so it knows how to properly write your changes back. Your help files have plenty of documentation and samples as to how this should be done, there is even a wizard to create a DataAdapter that will build the commands for you.

Am using OleDbCommandBuilder with the OleDbDataAdapter in order to store change/add info back to the Access database... Does this make a diference? Cooze Am truly noob with data bases in .NET... Am searching both web and MSN library for info, but so far, am only collecting pieces, dont have the skills to assemble them to solve the puzzle...

PS: Am getting truly confused with all this... Is there any kind soul who could post me an short example showing me the proper way of using insert command on DataAdapter...

This is my code to get you started in case you want to post some sample code:
Code:
DataTable dtInCCCli = Data2.InCCCli();
OleDbDataAdapter daInCCCli = dbEngine.getDataAdapter();
OleDbCommandBuilder cbInCCCli = new OleDbCommandBuilder(daInCCCli);

newRow = dtInCCCli.NewRow();

newRow["numero"] = dtFindCli.Rows[0]["numero"].ToString();
newRow["numdoc"] = this.txt_numDoc.Text;
newRow["coddoc"] = "FA";
newRow["descri"] = "Factura N
 
Last edited by a moderator:
Althought this thread issue was not resolved or received any further support for too long I will now declare that it is no longer active since I moved to mySQL and there is not the "null values" problem thing...

- THREAD CLOSED -
 
Back
Top