我在尝试创建新数据库时遇到错误:
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
我一直试图修复它一段时间但没有任何结果。 有谁知道我的代码有什么问题?
提前致谢