VB2008 Linq to SQL addnew objects not being persisted to datatable (Visual Basic) RRS feed

  • Question

  • I am new to Linq to SQL and am trying to persist web data extracted from popups (newwindow2 events) occurring in an axwebbrowser, but have been unable to persist new data between newwindow sessions. 


    The data fields I am trying to persist were created as properties in Linq to SQL data classes through the Visual Studio IDE, based on the underlying data schema of a single datatable in a local SQL server 2005 express database.  Because my data connection is through databound textbox controls, a datagrid, table adapter, and in-memory dataset, it is difficult to ascertain where persistence is failing in the connection chain to my SQL datatable.  My data connection logic is a follows:


    instantiate datacontext (db) and class (rc) in form namespace


    Public db As New rcDataContext

    Public rc As New rc


    when a popup (newwindow2) event occurs, populate datamembers for class rc

    and attempt to persist rc data using







    then the popup closes and the application waits for the next popup and newwindow2 event

    The problem is that new data supposedly saved to the dataset while the popup is active is not being persisted to the datatable and subsequent popup events.  I'm not sure whether this is because multiple instances of the rc class are being created, Linq to SQL does not recognize IPNotify changes, the application closes before the dataset is persisted to the datatable, or I have not programmed the O/R persistence correctly.


    At this point, I think I may be better off reverting to a more directly-connected ADO.NET data connection and append a datarow directly to the data table rather than rely upon Linq's more complex n-tier data model.  Adding records to an .mdb table or excel file would be fine for this purpose.


    Does anyone have any ideas or Visual Basic code which might be of assistance?





    Tuesday, May 27, 2008 2:41 AM


  • OK, I'll try to answer my own question.  I finally got it working, but I'm not exactly sure why.  With the same declarations:


    Private db As New rcDataContext

    Private rc As New rc


    After manipulating the objects and without explicitly calling INotify changes, the records were added to the underlying database with the following code:





    Again, I'm not exactly sure why, but Linq to SQL is sure a lot simpler than writing new records manually with ADO.NET.



    Thursday, June 5, 2008 5:57 PM