简体   繁体   English

vb.net 和 mysql '未知列(*'我制作的列 idb 中选定行的第一个字母'*)在 where 子句中

[英]vb.net and mysql 'unknown column (*'firstletter of selected row in column idb that i made'*) in where clause

在此处输入图片说明

i'm trying to delete the selected row, but when i click the button delete it gives me a warning我正在尝试删除选定的行,但是当我单击按钮删除时,它给了我一个警告

'unknown column 'c' in where clause. where 子句中的“未知列”c。

actually not only that rows ,but each rows that selected ''unknown column ( 'firstletter of selected row in column idb that i made' ) in where clause.实际上不仅是那些行,而且每一行都在 where 子句中选择了“未知列”( “我创建的idb 中选定行的第一个字母” )。

在此处输入图片说明

here are my codes.这是我的代码。

for public class公开课

Public Class DAFTAR_BUKU
    Dim Koneksi As New MySqlConnection
    Dim da As MySqlDataAdapter
    Dim ds As New DataSet
    Dim dt As New DataTable
    Dim command As MySqlCommand
    Dim id_cell As Char
    Dim i As Integer
    Dim query As String

for function delete用于函数删除

 Private Sub delete(kdbk As Char)

        Dim query As String = "delete from daftarbuku where idb= " & kdbk
        command = New MySqlCommand(query, Koneksi)

        Try
            Koneksi.Open()
            da.DeleteCommand = Koneksi.CreateCommand()
            da.DeleteCommand.CommandText = query

            If MessageBox.Show("sure", "delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.OK Then

                If command.ExecuteNonQuery() > 0 Then
                    MsgBox("DELETED")
                    cleartext()
                End If
            End If
            Koneksi.Close()
            DataGridView1.Rows.RemoveAt(i)
        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

for button delete用于按钮删除

Private Sub del_Click(sender As Object, e As EventArgs) Handles del.Click
        delete(id_cell)
        GRID()
End Sub

Based on your code, I am assuming that the column idb is integer.根据您的代码,我假设列idb是整数。 Therefore you are passing integer into your function which accept char .因此,您将整数传递给接受char的函数。

You can either change char to integer or change id_cell to id_cell.tostring .您可以将 char 更改为 integer 或将id_cell更改为id_cell.tostring

Also in your catch exception since you are using mysql, use ex as MySqlException and in MessageBox, MsgBox(ex.toString) .同样在您使用 mysql 的 catch 异常中,使用ex as MySqlException并在 MessageBox 中使用MsgBox(ex.toString)

You can understand better from the detailed exception error shown next time.你可以从下一次显示的详细异常错误中更好地理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM