我正在开发一个visual studio 2010项目,其中我创建一个数据库,然后我创建表,但每次我运行程序并单击按钮“创建表”消息出现错误:“无效的表名称”和“语法错误(查询表达式中缺少运算符.'ID'“任何人都可以帮助我吗?这是我的代码:
Imports System.Data.OleDb
Public Class table
Public Property Auditionees As String
Public Property TrainingAgencyDepartment As String
Public Property TrainingAgency As String
Public Property sID1 As String
Public Property sName1 As String
Public Property sField1 As String
Public Property sAge1 As String
Public Property sAddress1 As String
Public Property sContact1 As String
Public Property bkID2 As String
Public Property bkName2 As String
Public Property bkAddress2 As String
Public Property bkContact2 As String
Public Property bID3 As String
Public Property bAuditioned3 As String
Public Property bConfirmed3 As String
Public Property bSID3 As String
Public Property bBNUM3 As String
Private Sub queryCommand(ByVal query As String)
Try
Access.con.Open()
Dim cmd As New OleDbCommand(query, Access.con)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Invalid table name")
End Try
Access.con.Close()
End Sub
Private Access As New connection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim query As String = ""
query = "Create table " & Auditionees & " (AuditioneeeId counter primary key , AuditioneeName text, Talent text, Age int, Address text, Contact text ) "
queryCommand(query)
query = "Create table " & TrainingAgency & " (AgencyNumber counter primary key , AgencyName text, Address text, Contact text ) "
queryCommand(query)
query = "Create table " & TrainingAgencyDepartment & " (DepartmentID counter primary key , DateAuditioned date, DateConfirmed date, AuditioneeID int references ) " & Auditionees & _
" (AuditioneeId), AgencyNumber int unique references " & TrainingAgency & "(AgencyNumber)) "
queryCommand(query)
Form1.Show()
Me.Hide()
End Sub
结束班
答案 0 :(得分:1)
你应该调试。 尝试查找哪个queryCommand运行失败。它运行3次。
您应该检查,可能缺少其中一个表名。
您也可以调试到queryCommand,因为在连接失败时也可以获得“Invalid table name”。写出例外。