i successfully run my datagrid. i can add and delete records but i cannot change the value on my datagrid. what could be wrong. Please check out my codes :
Private Sub frmTables_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim comInsert As New OleDbCommand()
Dim comUpdate As New OleDbCommand()
Dim comDelete As New OleDbCommand()
Try
SSSTable_DS = DataService.GetDataSet("[Code No],format([Range1],#,##0.00) as Range1,format([Salary Credit],#,##0.00) as SalaryCredit,format([Employer Share],#,##0.00) as EmployerShare,format([Employee Share],#,##0.00) as EmployeeShare,format([EC Employer],#,##0.00) as ECC", "SSS Table")
comInsert.CommandText = "Insert into [SSS Table]([Code No],[Range1],[Salary Credit],[Employer Share],[Employee Share],[EC Employer]) values (?,?,?,?,?,?)"
comInsert.Connection = DataService.GetConnection
comInsert.Parameters.Add(New OleDbParameter("Code No", OleDbType.BigInt, 100, "Code No"))
comInsert.Parameters.Add(New OleDbParameter("Range1", OleDbType.Double, 100, "Range1"))
comInsert.Parameters.Add(New OleDbParameter("Salary Credit", OleDbType.Double, 100, "SalaryCredit"))
comInsert.Parameters.Add(New OleDbParameter("Employer Share", OleDbType.Double, 100, "EmployerShare"))
comInsert.Parameters.Add(New OleDbParameter("Employee Share", OleDbType.Double, 100, "EmployeeShare"))
comInsert.Parameters.Add(New OleDbParameter("EC Employer", OleDbType.Double, 100, "ECC"))
comUpdate.CommandText = "Update [SSS Table] set [Range1]=?,[Salary Credit]=?,[Employer Share]=?,[Employee Share]=?,[EC Employer]=? where [Code No]=?"
comUpdate.Connection = DataService.GetConnection
comUpdate.Parameters.Add(New OleDbParameter("Range1", OleDbType.Double, 100, "Range1"))
comUpdate.Parameters.Add(New OleDbParameter("Salary Credit", OleDbType.Double, 100, "SalaryCredit"))
comUpdate.Parameters.Add(New OleDbParameter("Employer Share", OleDbType.Double, 100, "EmployerShare"))
comUpdate.Parameters.Add(New OleDbParameter("Employee Share", OleDbType.Double, 100, "EmployeeShare"))
comUpdate.Parameters.Add(New OleDbParameter("EC Employer", OleDbType.Double, 100, "ECC"))
comUpdate.Parameters.Add(New OleDbParameter("Original_Code No", OleDbType.BigInt, 100, ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Code No", DataRowVersion.Original, Nothing))
comDelete.CommandText = "Delete from [SSS Table] where [Code No]=?"
comDelete.Connection = DataService.GetConnection
comDelete.Parameters.Add(New OleDbParameter("Original_Code No", OleDbType.BigInt, 100, ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Code No", DataRowVersion.Original, Nothing))
grdSTable.DataSource = Nothing
grdSTable.DataMember = String.Empty
SSSTable_DT = New DataTable("SSS Table")
SSSTable_DT = SSSTable_DS.Tables("SSS Table")
SSSTable_DV = New DataView(SSSTable_DT)
SSSTable_DV.AllowNew = True
SSSTable_DV.AllowEdit = True
SSSTable_DV.AllowDelete = True
DataService.m_da.InsertCommand = comInsert
DataService.m_da.UpdateCommand = comUpdate
DataService.m_da.DeleteCommand = comDelete
grdSTable.DataSource = SSSTable_DV
ssstablestyle.MappingName = "SSS Table"
AddColumnField("Code No", "Item No", HorizontalAlignment.Left, 65, ssstablestyle)
AddColumnField("Range1", "Min Range", HorizontalAlignment.Right, 100, ssstablestyle)
AddColumnField("SalaryCredit", "Salary Credit", HorizontalAlignment.Right, 100, ssstablestyle)
AddColumnField("EmployerShare", "Employer Share", HorizontalAlignment.Right, 115, ssstablestyle)
AddColumnField("EmployeeShare", "Employee Share", HorizontalAlignment.Right, 125, ssstablestyle)
AddColumnField("ECC", "EC Employer", HorizontalAlignment.Right, 75, ssstablestyle)
ssstablestyle.AlternatingBackColor = System.Drawing.Color.Lavender
ssstablestyle.BackColor = Color.White
ssstablestyle.GridLineStyle = DataGridLineStyle.None
grdSTable.TableStyles.Add(ssstablestyle)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub cmdAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAccept.Click
If SSSTable_DS.HasChanges Then
If MessageBox.Show("You are about to save all changes made in the Datagrid, Continue?", "Accept Changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
DataService.UpdateDS(SSSTable_DS, "SSS Table")
End If
End If
End Sub
Private Sub cmdDiscard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDiscard.Click
If SSSTable_DS.HasChanges Then
If MessageBox.Show("You are about to discard all changes made in the Datagrid, Continue?", "Undo Changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
SSSTable_DS.RejectChanges()
End If
End If
End Sub
Private Sub AddColumnField(ByVal Mapping_Name As String, ByVal Header_Text As String, ByVal Horizontal_Alignment As HorizontalAlignment, ByVal Column_Width As Double, ByVal Table_Style As DataGridTableStyle)
columnfield = New DataGridTextBoxColumn()
columnfield.MappingName = Mapping_Name
columnfield.HeaderText = Header_Text
columnfield.Alignment = Horizontal_Alignment
columnfield.Width = Column_Width
Table_Style.GridColumnStyles.Add(columnfield)
End Sub
Private Sub frmTables_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim comInsert As New OleDbCommand()
Dim comUpdate As New OleDbCommand()
Dim comDelete As New OleDbCommand()
Try
SSSTable_DS = DataService.GetDataSet("[Code No],format([Range1],#,##0.00) as Range1,format([Salary Credit],#,##0.00) as SalaryCredit,format([Employer Share],#,##0.00) as EmployerShare,format([Employee Share],#,##0.00) as EmployeeShare,format([EC Employer],#,##0.00) as ECC", "SSS Table")
comInsert.CommandText = "Insert into [SSS Table]([Code No],[Range1],[Salary Credit],[Employer Share],[Employee Share],[EC Employer]) values (?,?,?,?,?,?)"
comInsert.Connection = DataService.GetConnection
comInsert.Parameters.Add(New OleDbParameter("Code No", OleDbType.BigInt, 100, "Code No"))
comInsert.Parameters.Add(New OleDbParameter("Range1", OleDbType.Double, 100, "Range1"))
comInsert.Parameters.Add(New OleDbParameter("Salary Credit", OleDbType.Double, 100, "SalaryCredit"))
comInsert.Parameters.Add(New OleDbParameter("Employer Share", OleDbType.Double, 100, "EmployerShare"))
comInsert.Parameters.Add(New OleDbParameter("Employee Share", OleDbType.Double, 100, "EmployeeShare"))
comInsert.Parameters.Add(New OleDbParameter("EC Employer", OleDbType.Double, 100, "ECC"))
comUpdate.CommandText = "Update [SSS Table] set [Range1]=?,[Salary Credit]=?,[Employer Share]=?,[Employee Share]=?,[EC Employer]=? where [Code No]=?"
comUpdate.Connection = DataService.GetConnection
comUpdate.Parameters.Add(New OleDbParameter("Range1", OleDbType.Double, 100, "Range1"))
comUpdate.Parameters.Add(New OleDbParameter("Salary Credit", OleDbType.Double, 100, "SalaryCredit"))
comUpdate.Parameters.Add(New OleDbParameter("Employer Share", OleDbType.Double, 100, "EmployerShare"))
comUpdate.Parameters.Add(New OleDbParameter("Employee Share", OleDbType.Double, 100, "EmployeeShare"))
comUpdate.Parameters.Add(New OleDbParameter("EC Employer", OleDbType.Double, 100, "ECC"))
comUpdate.Parameters.Add(New OleDbParameter("Original_Code No", OleDbType.BigInt, 100, ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Code No", DataRowVersion.Original, Nothing))
comDelete.CommandText = "Delete from [SSS Table] where [Code No]=?"
comDelete.Connection = DataService.GetConnection
comDelete.Parameters.Add(New OleDbParameter("Original_Code No", OleDbType.BigInt, 100, ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Code No", DataRowVersion.Original, Nothing))
grdSTable.DataSource = Nothing
grdSTable.DataMember = String.Empty
SSSTable_DT = New DataTable("SSS Table")
SSSTable_DT = SSSTable_DS.Tables("SSS Table")
SSSTable_DV = New DataView(SSSTable_DT)
SSSTable_DV.AllowNew = True
SSSTable_DV.AllowEdit = True
SSSTable_DV.AllowDelete = True
DataService.m_da.InsertCommand = comInsert
DataService.m_da.UpdateCommand = comUpdate
DataService.m_da.DeleteCommand = comDelete
grdSTable.DataSource = SSSTable_DV
ssstablestyle.MappingName = "SSS Table"
AddColumnField("Code No", "Item No", HorizontalAlignment.Left, 65, ssstablestyle)
AddColumnField("Range1", "Min Range", HorizontalAlignment.Right, 100, ssstablestyle)
AddColumnField("SalaryCredit", "Salary Credit", HorizontalAlignment.Right, 100, ssstablestyle)
AddColumnField("EmployerShare", "Employer Share", HorizontalAlignment.Right, 115, ssstablestyle)
AddColumnField("EmployeeShare", "Employee Share", HorizontalAlignment.Right, 125, ssstablestyle)
AddColumnField("ECC", "EC Employer", HorizontalAlignment.Right, 75, ssstablestyle)
ssstablestyle.AlternatingBackColor = System.Drawing.Color.Lavender
ssstablestyle.BackColor = Color.White
ssstablestyle.GridLineStyle = DataGridLineStyle.None
grdSTable.TableStyles.Add(ssstablestyle)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub cmdAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAccept.Click
If SSSTable_DS.HasChanges Then
If MessageBox.Show("You are about to save all changes made in the Datagrid, Continue?", "Accept Changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
DataService.UpdateDS(SSSTable_DS, "SSS Table")
End If
End If
End Sub
Private Sub cmdDiscard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDiscard.Click
If SSSTable_DS.HasChanges Then
If MessageBox.Show("You are about to discard all changes made in the Datagrid, Continue?", "Undo Changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
SSSTable_DS.RejectChanges()
End If
End If
End Sub
Private Sub AddColumnField(ByVal Mapping_Name As String, ByVal Header_Text As String, ByVal Horizontal_Alignment As HorizontalAlignment, ByVal Column_Width As Double, ByVal Table_Style As DataGridTableStyle)
columnfield = New DataGridTextBoxColumn()
columnfield.MappingName = Mapping_Name
columnfield.HeaderText = Header_Text
columnfield.Alignment = Horizontal_Alignment
columnfield.Width = Column_Width
Table_Style.GridColumnStyles.Add(columnfield)
End Sub