mysql - 此错误是什么意思以及如何修复它 "Error in saving to database. error is: The method or operation is not implemented"?

标签 mysql vb.net

这些是我在“保存”按钮上的代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim dbCon As MySqlConnection
    Dim conStr As String

    conStr = "server=127.0.0.1;uid=root;pwd=;database=ps20150385"
    Try

    Catch ex As Exception

    End Try
    dbCon = New MySqlConnection(conStr)
    dbCon.Open()
    ' Add record to database
    Dim productName, productCat, unitPrice As String

    productName = Trim(TextBox1.Text)
    productCat = Trim(ComboBox1.Text)
    unitPrice = Trim(TextBox3.Text)


    Dim Sql As String = "INSERT INTO products (ProductName,ProductCat,UnitPrice) VALUES('" & TextBox1.Text & "' , '" & ComboBox1.Text & "' , '" & TextBox3.Text & "')"
    If TextBox1.Text = "" Or ComboBox1.Text = "" Or TextBox3.Text = "" Then
        MsgBox("Please! insert record")
    Else
        MsgBox("Record inserted successfully.")

    End If
    Try
        DbCommand = New MySqlCommand(Sql, dbconn)
        dbread = DbCommand.ExecuteReader()
        Me.Close()
    Catch ex As Exception
        MsgBox("Error in saving to Database. error is :" & ex.Message)
        TextBox1.Text = ""
        ComboBox1.Text = ""
        TextBox3.Text = ""
        Exit Sub

    End Try
    dbread.Close()
    TextBox1.Text = ""
    ComboBox1.Text = ""
    TextBox3.Text = ""

End Sub

最佳答案

首先出现的是您正在 INSERTcmd 上使用 .ExecuteReader()INSERT 应作为 .ExecuteNonQuery()

执行

弹出的第二件事是您只是要求进行 sql 注入(inject)攻击(有意或无意)。您应该使用参数,而不是在查询中包含 TextBox.Text。而不是直接字符串。如果不这样做,一个简单的特殊字符就会破坏您的查询。

关于mysql - 此错误是什么意思以及如何修复它 "Error in saving to database. error is: The method or operation is not implemented"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43116777/

相关文章:

vb.net - vb.net中是否有片段的$ end $版本?

Python-BeautifulSoup : How to save html into database?

MySQL 在行值中查找子字符串?

mysql - CodeIgniter NOW()插入: what's the fastest way?

mysql - 从表中选择每个成员的最大值

html - Visual Basic 登录页面导致错误(错误 BC30506 Handles 子句需要 WithEvents...)

PHP邮件发送MYSQL查询

vb.net - 在 VB.NET 中将 DataReader 的结果存储到数组中

vb.net - 控件名称重复导致 'Not A Member'编译错误

vb.net - 如何判断系统托盘中的气球提示是否已关闭?