1
我想在使用vb.net控制檯applicaiton MYSQL數據庫中創建表,我已經嘗試使用Visual Studio 2012運行它,它運行順利,但是當我嘗試使用VS 2012的構建創建一個.EXE文件,然後我複製文件在bin /調試它無法運行,因爲我部署到另一臺機器(我已經在機器上安裝了MYSQL連接6.8.3和.NET框架)。我已經嘗試調試它,問題發生在我的查詢中加入變量的地方。Mysql數據庫崩潰在.EXE vb.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()
謝謝你們。
它的工作吧!先生,非常感謝你! – user3287181
很高興爲您提供幫助,歡迎來到StackOverflow。只要記住接受/ upvote幫助你解決你的問題的答案。 – Steve
再次感謝XDDD先生! – user3287181