Chris
Mon Mar 03 11:40:54 CST 2008
On Mar 1, 7:38 am, "John" <J...@nospam.infovis.co.uk> wrote:
> If I use datareader to replace "fill" my form controls, what method can I
> use to update the values back to db?
>
Since you are using VS2008, you might consider using LINQ to SQL. If
your queries are not extremely complex, you won't have to write any
SQL at all. You would just call the SubmitChanges method of the
DataContext class:
' DataContext takes a connection string.
Dim db As New DataContext("...\database.mdf") 'Use appropriate
connection string here
' Get a typed table to run queries.
Dim Orders As Table(Of Order) = db.GetTable(Of Order)()
' Query the database for the row to be updated.
Dim ordQuery = _
From ord In Orders _
Where ord.OrderID = 11000 _
Select ord
' Execute the query, and change the column values
' you want to change.
For Each ord As Order In ordQuery
ord.ShipName = "Mariner"
ord.ShipVia = 2
' Insert any additional changes to column values.
Next
' Submit the changes to the database.
db.SubmitChanges()
Of course you would change the code to suit your needs but with this
example, you would have to create an Order class and set up the
mapping to the database, but that is a one time setup. Linq makes the
code much more readable. I can't say if this will solve your
performance hiccup though. Using LINQ does not guarantee high
performance and, indeed, if you don't construct your LINQ queries
properly, you could degrade performance. but often, readability and
maintainability are preferred over a minute performance degradation.
Your mileage may vary, of course.
See this for more information:
http://msdn2.microsoft.com/en-us/library/bb399408.aspx
Chris