I am trying to convert old VB6 code to VB.NET. The old code used DAO, and now I'm trying to replicate it to ADO.NET/OleDB. I made some achievements (I think ...), but now I canβt figure out how to add a DataTable to the database.
Here is the old VB6 code, td is a TableDef object from the DAO:
If fso.FileExists(loc) Then
Set td = m_db.CreateTableDef("Ratings")
td.Connect = "Excel 8.0;HDR=Yes;IMEX=2;DATABASE=" & loc
td.SourceTableName = "Sheet1$"
m_db.TableDefs.Append td
bFileNotExists = False
Else
bFileNotExists = True
End If
From what I understand, this is reading Sheet1 from the Excel "loc" file, and then adding it to m_db, the DAO database object. This is what I have so far, and please correct me if you see any errors, as I am just starting with this kind of thing -
If fso.FileExists(loc) Then
oleCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & loc & ";Extended Properties=""Excel 8.0;HDR=Yes;")
oleCon.Open()
oleAdapter = New OleDbDataAdapter("SELECT * FROM [Sheet1$]", oleCon)
oleAdapter.Fill(dt)
bFileNotExists = False
Else
bFileNotExists = True
End If
, TableDef DataTable (dt). , . , m_db.TableDefs.Append td . !