Mysql数据库崩溃在.EXE vb.net控制台文件上

时间:2014-02-08 13:30:56

标签: mysql vb.net

我正在尝试使用vb.net控制台应用程序在MYSQL数据库中创建表,我已经尝试使用Visual Studio 2012运行它并且它运行顺利但是当我尝试使用VS 2012的构建创建.EXE文件时我复制了bin / debug上的文件无法运行,因为我将它部署到另一台机器上(我已在机器中安装了MYSQL connect 6.8.3和.NET框架)。我已经尝试调试它,问题发生在我在查询中包含变量的地方。

这是代码。

导入MySql.Data.MySqlClient 模块模块1

Sub Main()
    toCreateTable()
End Sub

Private Sub toCreateTable()

    Dim varString As String = "tablenaming"

    Dim Query As String
    Dim con As MySqlConnection = New MySqlConnection("server=10.4.26.101; user=prolog;  database=db_prolog; port=3306; password=n0viru$;")
    con.Open()

    Query = "CREATE TABLE  '" & varString & "' ( usernames varchar(50) ) "

    Dim cmd As New MySqlCommand(Query, con)

    If (cmd.ExecuteNonQuery()) Then

    End If
    con.Close()

End Sub

结束模块

这是错误。

unhandled exception: mysql.data.mysqlclient.mysqlexception you have an error in your SQL syntax; check the manula that correspons to you MySQL server version for the right syntas to user near ''tblenaming' (usernames varchar(50)) )' at line 1
at mysql.data.mysqlclient.mysqlstream.readpacket()
at mysql.data.mysqlclient.nativdriver.getresult(int32& statementId, int32& affected Rows, int 64& insertedId)

at mysql.data.mysqlclient.driver.getresult(int32 statementId, Boolean force)
at mysql.data.mysqlclient.mysqldatareader.nextresult()
at mysql.data.mysqlcommand.executereader(commandbehavior behavior))
at mysql.data.mysqlclient.mysqlcommand.executenonquery()
at consolapplication15.module1.toCreateTable()
at consoleapplication.module1.main()

谢谢你们。

1 个答案:

答案 0 :(得分:0)

在MySql中,用于封装表或列名称的默认字符是反引号。不是单引号。尝试将代码更改为

Query = "CREATE TABLE `" & varString & "` ( usernames varchar(50) ) "

键入反引号按住 ALT 键并按数字键盘上的 096