TableAdapter not updating records

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

In Visual Studio 2005, I used the Data - Add New Data Source wizard to
create a new Table Adapter data set to interface to my SQL Server 2005
database.



Then I wrote this C# code to add new records to the database:



TradeRecordsDataSet TDataSet = new TradeRecordsDataSet();



DataRow NewRow = TDataSet.Tables["Trades"].NewRow();

NewRow["Symbol"] = Symbol;

NewRow["Mkt#"] = MktNo;

NewRow["MktType"] = MktType;



TDataSet.Tables["Trades"].Rows.Add(NewRow);

TDataSet.Tables["Trades"].AcceptChanges();



Everything executes properly, but when I open the table, there are no new
records. Does anybody know why my new records are not being committed to
the database?



Thanks in advance for any ideas.
 
TradeRecordsDataSet TDataSet = new TradeRecordsDataSet();
DataRow NewRow = TDataSet.Tables["Trades"].NewRow();
NewRow["Symbol"] = Symbol;
NewRow["Mkt#"] = MktNo;
NewRow["MktType"] = MktType;
TDataSet.Tables["Trades"].Rows.Add(NewRow);

TradesTableAdapter ta = new TradesTableAdaper();
ta.Update(TDataSet,"Trades");
TDataSet.Tables["Trades"].AcceptChanges();

Several points:

1) After you work with table adapters, you will discover that it is best to
stay far away from them.
2) You will want to replace them with data adapters. After working with
these for awhile, you will discover that designing them in the VS 2005 / VS
2003 designer is problematic at best.
3) It's not that hard to write your own designer that correctly writes all
the underlying Sql and correctly configures all the parameters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top