我试图在确定生成访问数据库之后使用vb.net创建.DBF文件,之后将其转换为.DBF在vb.net中实际上是不可能的
但是,现在我遇到了以下问题:
这是我正在使用的代码:
Imports System.IO
Imports System.Data.SqlClient
Public Class frmStart
Inherits System.Windows.Forms.Form
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim fd As FolderBrowserDialog = New FolderBrowserDialog
Dim strFileName As String = ""
Dim dbNameForm As New frmDatabaseName()
' init DB Vars
Dim ds As New DataSet
Dim sql As String
' Open Location browser
dbNameForm.FileName = "Test"
If dbNameForm.ShowDialog() = DialogResult.OK Then
MsgBox("Select the location where you want your Access-File")
If fd.ShowDialog() = DialogResult.OK Then
Dim DatabaseFullPath As String = fd.SelectedPath & "\" & dbNameForm.FileName & ".DBF"
'Create the Database
CreateDatabase(DatabaseFullPath)
MsgBox("Database created")
'Open database
Dim dBaseConnection As New System.Data.OleDb.OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DatabaseFullPath & ";" & _
"Extended Properties=dBase IV")
dBaseConnection.Open()
' Filling the Database with the required Columns
sql = "CREATE TABLE DB_Total (NAME varchar(79),TYPE varchar(16), UNIT varchar(31)," &
"ADDR varchar(254), RAW_ZERO varchar(11), RAW_FULL varchar(11), ENG_ZERO varchar(11)," &
"ENG_FULL varchar(11), ENG_UNITS varchar(8), FORMAT varchar(11), COMMENT varchar(254)," &
"EDITCODE varchar(8), LINKED varchar(1), OID varchar(10), REF1 varchar(11), REF2 varchar(11)," &
"DEADBAND varchar(11), CUSTOM varchar(128), TAGGENLINK varchar(32), CLUSTER varchar(16)," &
"EQUIP varchar(254), ITEM varchar(63), HISTORIAN varchar(6)," &
"CUSTOM1 varchar(254), CUSTOM2 varchar(254), CUSTOM3 varchar(254), CUSTOM4 varchar(254)," &
"CUSTOM5 varchar(254), CUSTOM6 varchar(254), CUSTOM7 varchar(254), CUSTOM8 varchar(254))"
Dim dBaseCommand As New System.Data.OleDb.OleDbCommand(sql, dBaseConnection)
dBaseCommand.ExecuteNonQuery()
dBaseCommand = Nothing
sql = "CREATE TABLE TagSubs (TAGNAME varchar(79), POLLTIME varchar(6), SCALEMODE varchar(8), DEADBAND varchar(15))"
dBaseCommand = New System.Data.OleDb.OleDbCommand(sql, dBaseConnection)
dBaseCommand.ExecuteNonQuery()
dBaseCommand = Nothing
dBaseConnection.Close()
Else
MsgBox("Action Cancelled")
End If
Else
MsgBox("Action Cancelled")
End If
End Sub
' Creating a Database
Private Function CreateDatabase( _
ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean = False
Dim cat As New ADOX.Catalog
Try
Dim sCreateString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
Finally
cat = Nothing
End Try
Return bAns
End Function
End Class
我也使用第二个表单,但这只是一个用户可以在文件中添加名称的窗口(默认,名称为“test.DBF”)
在我创建此代码后,我运行它,我收到以下错误:
C:\Documents and settings\HIJ541\Desktop\Test.DBF is not a Valid path.
Make sure the path name is spelled correctly and there is an active connection
with the server on which the file is located
(荷兰语粗略翻译)
此外,当我尝试打开创建的.DBF文件时,它会告诉我以下内容:
the file you are trying to open is in a different format than specified
by the file extension
我认为我真的很喜欢这个......任何帮助都会非常感激!
答案 0 :(得分:2)
我已经解决了我自己的问题。
显然,当您连接到.DBF文件时,您不应该输入完整路径名(包括文件名)
所以:
Dim DatabaseFullPath As String = fd.SelectedPath & "\" & dbNameForm.FileName & ".DBF"
应该是这样的:
Dim DatabaseFullPath As String = fd.SelectedPath & "\\"