我正在开发一个 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
下课
最佳答案
你应该调试。 尝试查找哪次 queryCommand 运行失败。它运行 3 次。
您应该检查一下,也许其中一个表名丢失了。
您还可以调试到 queryCommand,因为当连接失败时您也会得到“无效的表名”。也写出异常。
关于mysql - 查询表达式 '.ID' 中缺少运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40660552/