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.
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.
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. Therefore you are passing integer into your function which accept char .
You can either change char to integer or change id_cell
to id_cell.tostring
.
Also in your catch exception since you are using mysql, use ex as MySqlException
and in MessageBox, MsgBox(ex.toString)
.
You can understand better from the detailed exception error shown next time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.