开发者

.Net Simple Data File usage

开发者 https://www.devze.com 2023-02-18 06:02 出处:网络
I\'ve created a new project in .Net (2010 4.0) and added an SDF data file.I\'ve generated a dataset and created a table in it (and I believe generated the Fill and other methods).

I've created a new project in .Net (2010 4.0) and added an SDF data file. I've generated a dataset and created a table in it (and I believe generated the Fill and other methods).

In code, I'm trying to add a row to the database.

        eBureauScrubber.App_Data.matchingtempDataSet ds = new App_Data.matchingtempDataSet();
        eBureauScrubber.App_Data.matchingtempDataSet.ctfFileRow row = ds.ctfFile.NewctfFileRow();
        row.Address = "123 Main St.";
        row.City = "Overland Park";
        row.FirstName = "Matt";
        row.LastName = "Dawdy";
        row.rownum = 1;

EDIT: Added the next bit of code.

        ds.ctfFile.Rows.Add(row);
        ds.ctfFile.AcceptChanges();
        ds.AcceptChanges();

        eBureauScrubber.App_Data.matchingtempDataSetTableAdapters.ctfFileTableAdapter ctfa = new App_Data.matchingtempDataSetTableAdapters.ctfFileTableAdapter();
        ctfa.Update(ds.ctfFile);

This runs fine. However, after the program completes, the data is not persisted in the database. What am I missing?

EDIT: I've tried all different combinations of AcceptChanges() on the datatable, the dataset, running update() before, after, etc. I'm missing something huge here. I'm not even sure it is connecting to the "right" database. Maybe that's my problem.

EDIT 2: Here's what I did to get this to work (it's still funky, though).

  1. Change the properties of my DB file in App_Data to "Do Not Copy"
  2. Manually copy that db file to bin\debug\app_data
  3. Use the data adapter's fill method to fill the ds.ctf开发者_如何学PythonFile data table.
  4. Create a row (.NewctfFileRow())
  5. Set values on that row.
  6. ds.ctfFile.Rows.Add(row)
  7. ds.ctfFile.AcceptChanges();
  8. ds.AcceptChanges();
  9. Call the adapater's update method.

Now, the data is in my database file (in bin\debug\app_data), but I can't see it because the Data Sources connection. I'm still trying to find out how to do that.


It should have generated a TableAdapter class with a .Update() method that you have to call to save data in your database. See MSDN for some examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消