Insert ONE row into ONE table in ONE Mdb using OLEDB DataSet. FULL DISCLOSURE (No Pseudocode)
Posted on 2006-05-17
After many different (failed) attempts at the same seemingly BASIC task I am forced to go REMEDIAL in my question.
No points will be awarded unless the code or explanation is something that is verifiable and repeatable. I am sorry that I have to make this stipulation but I have had enough of the "soft" solutions I have found through MSDN,EE,etc. (i.e many different solution paths to do same thing that sometimes work and sometimes do not)
Something as oft-repeated as inserting A ROW into A DATABASE using an OLEDB DataSet MUST have a degenerate BASE command sequence that cannot be simplified further and WORKS every time. I realize there are a lot of factors to consider but I am only interested in the most BASIC checklist of requirements to get data into a table.
That being said here is the setup:
One MDB: MasterProblemList.mdb
One Table in MDB: MedicalProblemList
Five Fields in Table: UniqueID(PK),Teir1,Teir2,Teir3,Teir4
Objects in VB.Net code:
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"F:\BGV\Visual Studio Projects\VB.Net projects\Stack test\MedProblemListStacktest\MedProblemListStacktest\MasterProblemList.mdb"
Dim cnn As New OleDb.OleDbConnection 'Connection
Dim ds As New Data.DataSet() 'Dataset
Dim dtMPL As New DataTable 'Table
Dim daMPL As New OleDb.OleDbDataAdapter 'Data adapter
Dim drMPL As DataRow 'Datarow
Dim dtmMPL As New DataTableMapping 'Table mapping
Dim cmd As New OleDb.OleDbCommand 'Command
Question: In order to INSERT ONE ROW into the MDB,what sequence of commands and assignments (using these objects) is required? I am particuliarly interested in what mechanism actually writes the DataSet changes to the source database. Yeah, I've tried .Update with .EndEdit,etc.-doesn't do a thing. Again-verifiable and repeatable steps only.