Using LINQ to write?

jsurpless

Well-known member
Joined
Jul 29, 2008
Messages
144
Programming Experience
Beginner
Hi all

Up to this point, I've just been reading from my Access DB (importing info into AutoCAD) using the LINQ which I've found particularly easy to use in selecting a single specific record and then particular fields of that record...

Dim DatabaseDrawing_Table_Query = From Drawing_Record In DatabaseDrawing_Table.AsEnumerable() Select Drawing_Record _
Where (Drawing_Record.Field(Of Object)(c_Database.DrawingFileName_Field) = strAutoCADFile)

and then once I have my single record, I access the field I want like so

'Update Block Attribute Value from Database Component Table
AutoCAD_Block_Attribute.TextString = Drawing_Record.Field(Of Object)(strAutoCAD_Block_Attribute_Database)

Now, I'd like to reverse the process and take data from AutoCAD, writing it to my DB... can I use LINQ to do this OR is there a different method?

Many thanks!
 
Hi

Thanks for the link... wanted to ask you if the following might work...

VB.NET:
Drawing_Record.BeginEdit()
Drawing_Record.Item(strAutoCAD_Block_Attribute_Database) = AutoCAD_Block_Attribute.TextString
Drawing_Record.AcceptChanges()
Drawing_Record.EndEdit()

This *seems* to be working but I'm assuming that I'm only making changes to my data-table until I somehow write that table back to Access...

Is there a way to push the table back? I saw this method in what you linked

VB.NET:
Private Sub UpdateButton_Click(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) _
                               Handles UpdateButton.Click
  Dim updateCust = (From cust In db.Customers _
                    Where cust.CustomerID = "JILLF").ToList()(0)

  updateCust.ContactName = "Jill Shrader"

  Try
    db.SubmitChanges()
  Catch
    ' Handle exception.
  End Try

  RefreshData()
End Sub

but I was wondering if there was another way - mainly because I am already familiar with my method AND I have variable field names (the names are specified in an XML file keyed to the AutoCAD attribute)

Thanks!
 
Last edited:
Point being, LINQ does integrated queries in client side code, it can be used it with any enumerable object. With LINQ To SQL the database objects maps directly to strongly typed client side objects and using LINQ agaist these and the DataContext proxy provides real time interaction with the DB. Returned objects is still a local cache that can be changed and submitted back to DB, the submission requires an explicit call. The difference to the traditional approach is that you have to submit queries to the DB throught a command/adapter object you have to configure, then you can do Linq expressions with the local cache of data, changes have to be made against this cache, then updates must be made through the command/adapter to db as normal.

For help with traditional data access methods I suggest you ask in the Data Access forums or DataBase section of forums.
 
Back
Top