Here is my first attempt. I am getting an error that the "DataSource cannot be empty" when I try to open the connection and build the table. I have not coded the transaction part yet. I just wanted to see if the database and table were created with the schema. gMsg is for a message box used for debugging.
*******************Begin Code Snippet******************
With dlgSaveFile .InitialDirectory = My.Computer.FileSystem.GetParentPath(txtExcelFileName.Text)
.Filter =
"SQLite3 Database *.s3db|*.s3db"
.FilterIndex = 1
If .ShowDialog <> Windows.Forms.DialogResult.OK Then Exit SubstrSQLiteConn = "DataSource = " & .FileName
End WithSQLiteConn = New SQLite.SQLiteConnection(strSQLiteConn)
SQLiteConn.Open()
gMsg = "Data Types: " & vbCrLf
CreateTableString = CreateTableBaseString & cboSheetName.SelectedText
Dim nbrParm As Short = dtExcel.Columns.Count
Dim parmList As SQLite.SQLiteParameter()ReDim parmList(nbrParm - 1)
Dim I As Integer = 0For Each myDataColumn In dtExcel.ColumnsgMsg += "Column " & myDataColumn.ColumnName & ": data type = " & myDataColumn.DataType.ToString & vbCrLf
myDataType = myDataColumn.DataType.ToString
Select Case myDataType
Case Is = "System.Double"
myDataType =
"FLOAT"
Case Is = "System.Decimal"
myDataType =
"FLOAT"
Case Is = "System.String"
myDataType =
"VARCHAR(1000)"
Case Is = "System.DateTime"
myDataType =
"DATETIME"
Case Else
myDataType =
"VARCHAR(500)"
End Select
CreateColumnString += myColumnName &
" " & myDataType & ", "Dim holdParm As New SQLiteParameter
With holdParm.ParameterName = "@" & myDataColumn.ColumnName
End With
parmList(I) = holdParm
Next myDataColumn
CreateColumnString = CreateColumnString +
")"CreateColumnString = Replace(CreateColumnString, ", )", ")")
CreateTableString = CreateTableString & CreateColumnString
Using cmdCreateTable As SQLiteCommand = SQLiteConn.CreateCommandWith cmdCreateTable
.CommandType = CommandType.Text
.CommandText = CreateTableString
.Parameters.AddRange(parmList)
.ExecuteNonQuery()
End WithDim trans As SQLiteTransaction = cmdCreateTable.Transaction
End Using
*******************End Code Snippet******************