尝试在VB.NET中使用参数化查询创建数据库时出现MySQL语法错误

时间:2017-08-13 22:04:14

标签: mysql vb.net

我在尝试创建新数据库时遇到错误:

Function CreateDatabase(ByVal Name As String) As Boolean
        Dim Query As New MySqlCommand
        Query.Connection = Connection

'MySqlConnection在之前的函数中打开,这很有效。

        Query.CommandText = "CREATE DATABASE @database;"
        Query.Prepare()

        Query.Parameters.AddWithValue("@database", Name)

        Try
            Dim AffectedRows As Integer = Query.ExecuteNonQuery()
            If AffectedRows > 0 Then
                Return True
            Else
                Connection.Close()
                Return False
            End If

        Catch ex As Exception
            Connection.Close()
            Return False
        End Try

    End Function

ExecuteNonQuery调用发生错误,如下所示:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''nameofdatabase'' at line 1

我一直试图修复它一段时间但没有任何结果。 有谁知道我的代码有什么问题?

提前致谢

0 个答案:

没有答案