请VB高手帮我看看,为什么这里会出错呢?

来源:百度知道 编辑:UC知道 时间:2019/10/16 05:41:35
Public Sub CreateDB(ByVal DBFileStr As String)
Dim cnStr As String '# 数据库联接串
Dim sSql As String '# SQL语句变量

Dim f As New FileSystemObject
Dim cat As New ADOX.Catalog
Dim i As Integer
Dim f1
Set cn = New ADODB.Connection

On Error GoTo ERR
If f.FileExists(App.Path & "\songbase.mdb") = True Then

Kill App.Path & "\songbase.mdb"
End If

cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\" & DBFileStr & ".mdb;Jet OLEDB:Database Password="
cat.Create cnStr
cn.Open cnStr

sSql = "CREATE TABLE income" & _
"(日期 VARCHAR(255) NOT NULL IDENTITY PRIMARY KEY," & _
"时间 VARCHAR(255) NULL," & _
"收入原因 VARCHAR(255) NULL," & _
"收入金额 VARCHAR(255) NULL," & _
"支出原因 VARCHAR(255) NULL," & _
"支出金额 VARCHAR(255) NULL," & _
"借款 VARCHAR(255) NULL," & _
"还款 VARCHAR(255) NULL " & _
"备注 VARCHAR(255) NULL " & _
")"

cn.Execute sSql, adExecuteNoRecords
cn.Close

ERR:
MsgBox ERR.Description, vbOKOnly + vbExclamation, "错误!"

End Sub

这时运行会弹出"create table语句中的语法错误"
我把sSql改成:
sSql = "CREATE TABLE income" & _
"(日期 VARCHAR(255) NOT NULL IDENTITY PRIMARY KEY," & _
"时间 VARCHAR(255) NULL," & _
"收入原因 VARCHAR(255) NULL," & _
"收入金额 VARCHAR(255) NULL," & _
"支出原因 VARCHAR(255) NULL," & _
"支出金额 VARCHAR(255) NULL," & _
"借款 VARCHAR(255) NULL," & _
"还款 VARCHAR(255) NULL " & _
")"
也就是少了个"备注"的字段,就没问题,这是为什么呢

"还款 VARCHAR(255) NULL " & _
这行里NULL后面少了个逗号

数据库里的字段类型不一样吧?把VARCHAR改改看看

楼上是高手 看的真仔细
我每看出什么问题...