A
ahmeddc
Guest
Hello
The following code is used to delete a specific row in a DATAGRIDVIEW
The code works
The code does not update the data after deletion
FULL CODE
Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\ONLINESERVERTOME.accdb;Jet OLEDBatabase Password=12345")
Public DataSet1 As New DataSet
Public DataAdapter1 As New OleDbDataAdapter
Sub conn()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM TB_WEBSERVERPAYED", con)
DataAdapter1 = New OleDbDataAdapter(cmd)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(DataAdapter1)
DataSet1.Clear()
DataAdapter1.Fill(DataSet1, "TB_WEBSERVERPAYED")
DATAGRID_SERVER.DataSource = DataSet1
DATAGRID_SERVER.DataMember = "TB_WEBSERVERPAYED"
DATAGRID_SERVER.Refresh()
End Sub
Private Sub SERVERME_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
conn()
DATAGRID_SERVER.Columns(0).Width = 40
DATAGRID_SERVER.Columns(1).Width = 90
DATAGRID_SERVER.Columns(2).Width = 110
DATAGRID_SERVER.Columns(3).Width = 110
DATAGRID_SERVER.Columns(4).Width = 110
DATAGRID_SERVER.Columns(5).Width = 110
DATAGRID_SERVER.Columns(6).Width = 150
DATAGRID_SERVER.Columns(0).HeaderText = "ID"
DATAGRID_SERVER.Columns(1).HeaderText = "WEB CODE"
DATAGRID_SERVER.Columns(2).HeaderText = "WEB COSTDOLLAR"
DATAGRID_SERVER.Columns(3).HeaderText = "WEB COSTCOUNTRY"
DATAGRID_SERVER.Columns(4).HeaderText = "FULL PERIOD"
DATAGRID_SERVER.Columns(5).HeaderText = "START DATE"
DATAGRID_SERVER.Columns(6).HeaderText = "END DATE"
DATAGRID_SERVER.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DATAGRID_SERVER.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
count()
Catch ex As Exception
End Try
End Sub
Public Sub count()
Dim records, current As Integer
records = Me.BindingContext(DataSet1, "TB_WEBSERVERPAYED").Count
current = Me.BindingContext(DataSet1, "TB_WEBSERVERPAYED").Position + 1
Label2.Text = " COUNT RECORD " & current.ToString & " FROM " & records.ToString
For i As Integer = 0 To DATAGRID_SERVER.Rows.Count - 1
DATAGRID_SERVER.Rows(i).HeaderCell.Value = (i + 1).ToString
Next
End Sub
Private Sub BT_DELETE_Click(sender As System.Object, e As System.EventArgs) Handles BT_DELETE.Click
Try
Dim constr = "provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\ONLINESERVERTOME.accdb;Jet OLEDBatabase Password=12345"
Dim con As OleDbConnection = New OleDbConnection(constr)
Dim sql = "Delete From TB_WEBSERVERPAYED WHERE WEBSERVERPAYED_ID= @WEBSERVERPAYED_ID"
Dim sda As OleDbDataAdapter = New OleDbDataAdapter(sql, constr)
Dim com As OleDbCommand = New OleDbCommand(sql, con)
con.Open()
Dim indx As Integer = DATAGRID_SERVER.CurrentRow.Index
com.Parameters.AddWithValue("@WEBSERVERPAYED_ID", DATAGRID_SERVER(0, indx).Value.ToString())
com.ExecuteNonQuery()
DATAGRID_SERVER.Refresh()
conn()
MsgBox("DELETE DON")
Catch ex As Exception
MsgBox("ERROR")
Finally
con.Close()
End Try
End Sub
Continue reading...
The following code is used to delete a specific row in a DATAGRIDVIEW
The code works
The code does not update the data after deletion
FULL CODE
Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\ONLINESERVERTOME.accdb;Jet OLEDBatabase Password=12345")
Public DataSet1 As New DataSet
Public DataAdapter1 As New OleDbDataAdapter
Sub conn()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM TB_WEBSERVERPAYED", con)
DataAdapter1 = New OleDbDataAdapter(cmd)
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(DataAdapter1)
DataSet1.Clear()
DataAdapter1.Fill(DataSet1, "TB_WEBSERVERPAYED")
DATAGRID_SERVER.DataSource = DataSet1
DATAGRID_SERVER.DataMember = "TB_WEBSERVERPAYED"
DATAGRID_SERVER.Refresh()
End Sub
Private Sub SERVERME_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
conn()
DATAGRID_SERVER.Columns(0).Width = 40
DATAGRID_SERVER.Columns(1).Width = 90
DATAGRID_SERVER.Columns(2).Width = 110
DATAGRID_SERVER.Columns(3).Width = 110
DATAGRID_SERVER.Columns(4).Width = 110
DATAGRID_SERVER.Columns(5).Width = 110
DATAGRID_SERVER.Columns(6).Width = 150
DATAGRID_SERVER.Columns(0).HeaderText = "ID"
DATAGRID_SERVER.Columns(1).HeaderText = "WEB CODE"
DATAGRID_SERVER.Columns(2).HeaderText = "WEB COSTDOLLAR"
DATAGRID_SERVER.Columns(3).HeaderText = "WEB COSTCOUNTRY"
DATAGRID_SERVER.Columns(4).HeaderText = "FULL PERIOD"
DATAGRID_SERVER.Columns(5).HeaderText = "START DATE"
DATAGRID_SERVER.Columns(6).HeaderText = "END DATE"
DATAGRID_SERVER.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DATAGRID_SERVER.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
count()
Catch ex As Exception
End Try
End Sub
Public Sub count()
Dim records, current As Integer
records = Me.BindingContext(DataSet1, "TB_WEBSERVERPAYED").Count
current = Me.BindingContext(DataSet1, "TB_WEBSERVERPAYED").Position + 1
Label2.Text = " COUNT RECORD " & current.ToString & " FROM " & records.ToString
For i As Integer = 0 To DATAGRID_SERVER.Rows.Count - 1
DATAGRID_SERVER.Rows(i).HeaderCell.Value = (i + 1).ToString
Next
End Sub
Private Sub BT_DELETE_Click(sender As System.Object, e As System.EventArgs) Handles BT_DELETE.Click
Try
Dim constr = "provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\ONLINESERVERTOME.accdb;Jet OLEDBatabase Password=12345"
Dim con As OleDbConnection = New OleDbConnection(constr)
Dim sql = "Delete From TB_WEBSERVERPAYED WHERE WEBSERVERPAYED_ID= @WEBSERVERPAYED_ID"
Dim sda As OleDbDataAdapter = New OleDbDataAdapter(sql, constr)
Dim com As OleDbCommand = New OleDbCommand(sql, con)
con.Open()
Dim indx As Integer = DATAGRID_SERVER.CurrentRow.Index
com.Parameters.AddWithValue("@WEBSERVERPAYED_ID", DATAGRID_SERVER(0, indx).Value.ToString())
com.ExecuteNonQuery()
DATAGRID_SERVER.Refresh()
conn()
MsgBox("DELETE DON")
Catch ex As Exception
MsgBox("ERROR")
Finally
con.Close()
End Try
End Sub
Continue reading...