如何新建一个数据库,并添加一个由datarow()转换来的datatable?
我用vb2012+sqlite学习编程,我通过用datarow()转换得来一个表xmb1,我想把这个xmb1添加到一个新建的数据库中,怎么办?我是如下办的,但没有成功。Dim sqlcmmdt As New SQLiteCommand
Dim SQLconn_tp As New System.Data.SQLite.SQLiteConnection '定义系统模板数据库链接对象
Dim cUserNodeName As String = TreeView1.SelectedNode.Name
Dim dXmbExportDataRow As DataRow() = ds.Tables("xmname").Select("treedate like '" & cUserNodeName & "%'", "treedate") '筛选出数据到数据行
Dim cExportFileName As String = TreeView1.SelectedNode.Parent.Parent.Text & "-" & TreeView1.SelectedNode.Parent.Text & "-" & TreeView1.SelectedNode.Text & ".db" ‘得到文件名
Dim cFileDir As String
Dim fbd As New FolderBrowserDialog
fbd.ShowDialog() ’文件选择目录
If fbd.SelectedPath.Length <> 0 Then
cFileDir = fbd.SelectedPath
Else
Exit Sub
End If
SQLiteConnection.CreateFile(cFileDir & cExportFileName) ‘新建一个空数据库
SQLconn_tp = New SQLiteConnection()
SQLconn_tp.ConnectionString = "data source=" & cFileDir & cExportFileName '链接数据库
SQLconn_tp.Open()
sqlcmmdt.Connection = SQLconn_tp
Dim xmb1 As System.Data.DataTable = dXmbExportDataRow.CopyToDataTable() ’数据行转换为datatable
'下一步,计划把该表xmb1添加到数据库中。
看到sqlite教程中代码,复制表:CREATE TABLE new_table SELECT * FROM original_table
改为 代码:
= "CREATE TABLE xmb SELECT * FROM xmb1"
sqlcmmdt.ExecuteNonQuery()
但不成功,提示SQL logic 错误。请高手帮忙看一下是怎么回事?