Strongly Typed Data Set InsertCommand not working

  • Thread starter Thread starter mark6139
  • Start date Start date
M

mark6139

I have created a strongly typed dataset in C# using "Generate DataSet"
from the schema viewer/designer in Visual Studio .Net 2003. And I'm
using this in a Windows Forms application.

The database is an Access file.

I have created the associated data adapter and added an insert command
using the command builder wizard.

The resulting code for the insert command looks like this:

//---------------
this.simsInsertCommand.CommandText = "INSERT INTO Sims(simNum,
simTitle) VALUES (?, ?)";
this.simsInsertCommand.Connection = this.conContent;
this.simsInsertCommand.Parameters.Add(new
System.Data.OleDb.OleDbParameter( "simNum",
System.Data.OleDb.OleDbType.Integer, 0, "simNum"));
this.simsInsertCommand.Parameters.Add(
new System.Data.OleDb.OleDbParameter("simTitle",
System.Data.OleDb.OleDbType.VarWChar, 50, "simTitle"));
this.dtaSims.InsertCommand = this.simsInsertCommand;
//----------------

And my code for testing purposes to create a new row and update it in
the database:

//--------------------
dtsSims.SimsRow sr =
(dtsSims.SimsRow)dataSetInstance.Sims.NewSimsRow();
sr.BeginEdit();
sr.simNum = 33;//this is an auto number column and it also doesn't
work if
//I leave this out
sr.simTitle = "Test case";
sr.EndEdit();

dtaSims.Update(dataSetInstance.Sims);
//-------------------------------------

I get no error but also see no change to the database.

Could someone please tell me what I am missing?

Thanks for any suggestions,

Mark
 
Mark,

Your new created datarow is in my opinion not added to your datatable.

Not strongly typed that is
\\\
ds.Tables[x].Rows.Add(datarow);
///
I assume you can translate that to your Sims dataset.

I hope this helps,

Cor
 
Cor,

That was it.

I had thought the New[tablename]row method would add the row to the
table in the dataset.

Thank you VERY much.

Mark
 
Back
Top