Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted
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.
Posted (edited)
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' date=' 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.[/quote']

 

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, don't 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:

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º" + this.txt_numDoc.Text;
newRow["db"] = dTotalSum;

dtInCCCli.Rows.Add(newRow);
daInCCCli.Update(dtInCCCli);

Edited by EFileTahi-A
  • 2 weeks later...
Posted

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 -

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...