I am a VERY advanced VBA programmer making my way into VB.net.
So far, I have set up a MyDatabase.mdf database file in visual studio, and followed tutorials to make pretty forms that allow the user to view and update the data.
Now what I want to do is manipulate the data with VB code - go through all the records in tblTable and do complex algorithms that can't be done with SQL statements, and update the data in tblTable to reflect the calculated values. It seems like I can do this with code like this:
x = MyDatabaseDataSet.tblTable.rows(1).Field(Of String)("Field1")
x=ComplexCalculation(x)
MyDatabaseDataSet.tblTable.rows(1).SetField(Of String)("Field1",x)
But, from what I'm reading, the proper way to do this is to
1. Create a DataTable variable,
2. Load the table records I want to manipulate into that,
3. Edit the records in the DataTable,
4. Load the DataTable back into my database
I've found hundreds of resources telling me how to do #1 and #3, but I can't figure out how to do #2 and #4. I can't even guess how #4 would work - do you overwrite all the data in the table? Isn't this terribly inefficient, and wouldn't it cause issues if other people were accessing the database at the same time? (eg, this function would overwrite changes other users had made between steps #2 and #4)
Hope I don't sounds like an idiot.
Thanks!
So far, I have set up a MyDatabase.mdf database file in visual studio, and followed tutorials to make pretty forms that allow the user to view and update the data.
Now what I want to do is manipulate the data with VB code - go through all the records in tblTable and do complex algorithms that can't be done with SQL statements, and update the data in tblTable to reflect the calculated values. It seems like I can do this with code like this:
x = MyDatabaseDataSet.tblTable.rows(1).Field(Of String)("Field1")
x=ComplexCalculation(x)
MyDatabaseDataSet.tblTable.rows(1).SetField(Of String)("Field1",x)
But, from what I'm reading, the proper way to do this is to
1. Create a DataTable variable,
2. Load the table records I want to manipulate into that,
3. Edit the records in the DataTable,
4. Load the DataTable back into my database
I've found hundreds of resources telling me how to do #1 and #3, but I can't figure out how to do #2 and #4. I can't even guess how #4 would work - do you overwrite all the data in the table? Isn't this terribly inefficient, and wouldn't it cause issues if other people were accessing the database at the same time? (eg, this function would overwrite changes other users had made between steps #2 and #4)
Hope I don't sounds like an idiot.
Thanks!