mysql - 查询表达式 '.ID' 中缺少运算符

标签 mysql sql

我正在开发一个 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 次。

您应该检查一下,也许其中一个表名丢失了。

您还可以调试到 qu​​eryCommand,因为当连接失败时您也会得到“无效的表名”。也写出异常。

关于mysql - 查询表达式 '.ID' 中缺少运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40660552/

相关文章:

mysql - GROUP BY 子句在 sqlite 中获取逗号分隔值

php - 创建 SQL 查询,根据满足的条件对结果进行排序

mysql - SQLSTATE[HY000] : General error: 1364 Field 'id' doesn't have a default value in Laravel 6

php - 在查询中放置 IF (MYSQL)

java - 从 ResultSet Java 获取主键列

mysql - 在不知道行名称的情况下删除多行

MySQL - 查询将整数按位字段拆分为每个位的 bool 列

mysql - 带有字母的 Microsoft Access 号码字段

java - java HttpURLConnection 和 php 服务器中的登录系统

php - 如何在textarea中添加空行