我在 VB.net 中有一个程序,它在运行时确定表是否存在。如果它不存在,我想在 SQL Server 上创建一个与本地 FoxPro 表具有相同架构的表。这是可以做到的吗?
这是我到目前为止所拥有的。现在它只是从 Visual Foxpro 表中获取 Schema 并显示它。不知道从这里去哪里。有任何想法吗?
Private Sub dwprm01()
Try
Dim tableName As String = "dwprm01"
Dim tableExists As Boolean = False
Dim foxConn As New OleDbConnection("Provider=vfpoledb.1;Data Source=Z:\update_dwprm01\" & tableName & ".DBF;Collating Sequence=general;")
sConn.Open()
Dim restrictions(3) As String
restrictions(2) = tableName
Dim dbTbl As DataTable = sConn.GetSchema("Tables", restrictions)
Console.WriteLine("Checking if " & tableName & " exists")
If dbTbl.Rows.Count = 0 Then
'Table does not exist
tableExists = False
Console.WriteLine(tableName & " does not exist")
Console.WriteLine()
Console.WriteLine("Creating " & tableName)
Dim fSQL = "SELECT * FROM " & tableName
Dim cmd As New OleDbCommand(fSQL, foxConn)
foxConn.Open()
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Dim schema As DataTable = myReader.GetSchemaTable()
For Each row As DataRow In schema.Rows
For Each col As DataColumn In schema.Columns
Console.WriteLine(col.ColumnName & " = " & row(col).ToString())
Next
Next
myReader.Close()
foxConn.Close()
Else
'Table exists
tableExists = True
Console.WriteLine(tableName & " exists")
End If
dbTbl.Dispose()
sConn.Close()
sConn.Dispose()
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub