Hi,
I am using vb.net 2008 with MySQL for my project.
I have a datagridview on my form which displays records from Mysql table on form load.
i want to delete the selected row in datagrid from table on 'row header mouse click' event.
The 2 different codes that i tried --- deletes the record from the datagrid for a moment but does not delete from mysql table & re-appears when closed & debugged again.
Need help for the code which affects mysql table for deleting the selected record from datagrid.
my code is as below.
Have tried using 2 different codes seperately but both returns the same result as mention above.
*Plz note that i have also tried using the "code (2)" that is commented below "code(1)"
*Plz point out the mistakes (if any) in the current code & help out wit additional coding that is required.
mports MySql.Data.MySqlClient
Public Class Form1
Public Con As New MySqlConnection
Public mycmd As New MySqlCommand
Public mycmdbldr As MySqlCommandBuilder
Dim Connstr, indt As String
Dim cmdtext As String
Dim Msadptr As MySqlDataAdapter
Dim myTable As DataTable
Dim dr As MySqlDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dgvUsr2.RowHeadersVisible = True
dgvUsr2.Show()
Connstr = "Server=localhost;user id = root;password=root;database=hdams;"
cmdtext = "Select usr_id AS 'User Id',User_type AS 'User Type',fname AS 'First Name',mname AS 'Middle Name',lname AS 'Last Name',party_name AS 'Company',Join_dt AS 'Join Date',username,paswrd from user"
Try
Msadptr = New MySqlDataAdapter(cmdtext, Connstr)
myTable = New DataTable
Msadptr.Fill(myTable)
dgvUsr2.DataSource = myTable
Catch ex As Exception
End Try
End Sub
Private Sub dgvUsr2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvUsr2.MouseClick
'code(1)
dgvUsr2.Rows.Remove(dgvUsr2.CurrentRow)
'code (2)_______________________________________
'Dim Dr As DataRow
'Dr = myTable.Rows.Item(dgvUsr2.CurrentRow.Index)
'Dr.Delete()
'myTable.AcceptChanges()
'Con.Open()
'Connstr = "Server=localhost;user id = root;password=root;database=hdams;"
'cmdtext = "Select usr_id AS 'User Id',User_type AS 'User Type',fname AS 'First Name',mname AS 'Middle Name',lname AS 'Last Name',party_name AS 'Company',Join_dt AS 'Join Date',username,paswrd from user"
'Msadptr = New MySqlDataAdapter(cmdtext, Connstr)
'myTable = New DataTable
'Msadptr.Fill(myTable)
'dgvUsr2.DataSource = myTable
'Con.Close()
MessageBox.Show("A RECORD IS DELETED")
Catch
End Try
End Sub
End Class
Any HELP would be just great!!
Thanks in advance