how to delete selected row from database in GridControl - sql

I am new on DevExpress. I retrieve data from database to gridview and can display them so far. However, I have a button which makes several modifications when user clicks on it.
I can remove the selected row from gridview.
So my obvious question is how can I delete selected rows from database in gridview.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim cevap As DialogResult = DevExpress.XtraEditors.XtraMessageBox.Show("Are you sure?", "Dikkat!", MessageBoxButtons.YesNo)
If cevap = Windows.Forms.DialogResult.No Then Exit Sub
Dim command As New SqlCommand()
command.Connection = spcc.SqlCon
'command.CommandText = "DELETE FROM EBARPARAMETER WHERE ID = '" & GridView1.what? & "' "
Dim read As SqlDataReader
read = command.ExecuteReader()
GridView1.DeleteRow(GridView1.FocusedRowHandle)

Take a look at the Posting Data to a Connected Database help-article:
The GridView.DeleteRow method removes a row from a grid's View and also deletes the object which represents this row in the GridControl's data source, but not from a database. To accomplish your task, you need to post changes to the database manually, for example using corresponding the methods of a Data Adapter object or EF-context.
GridView1.what?
To get row objects that correspond to specific row handles, use the ColumnView.GetRow or ColumnView.GetDataRow method.
In specific cases, you may need to obtain indexes of rows in the bound data source that correspond to specific row handles in Views. To do this, use the ColumnView.GetDataSourceRowIndex method.

Related

ComboBox shows the first item when loaded into new form VB.Net

I have two forms which are connected, the first one has a datagridview(DGV) that will show list of staff.
When I double click the row the data from the FGV will transfer into second form for user to edit the data. Each column from the DGV will insert at textbox combobox etc.
But the combobox on second form are using database when I double click the DGV; the others is fine but for combobox it will show the first data in database.
This is the code for the double click on the first form:
Private Sub DataGridView1_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Dim frmEdit As New Edit
frmEdit.lblEENo.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString
frmEdit.txtName.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString
frmEdit.txtAge.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString
frmEdit.lblAgeCategory.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString
frmEdit.txtGender.Text = DataGridView1.CurrentRow.Cells(5).Value.ToString
frmEdit.cbEthnicity.Text = DataGridView1.CurrentRow.Cells(6).Value.ToString
frmEdit.cbGrade.Text = DataGridView1.CurrentRow.Cells(7).Value.ToString
frmEdit.cbCategory.Text = DataGridView1.CurrentRow.Cells(8).Value.ToString
frmEdit.cbDepartment.Text = DataGridView1.CurrentRow.Cells(9).Value.ToString
frmEdit.cbPosition.Text = DataGridView1.CurrentRow.Cells(10).Value.ToString
frmEdit.txtReporting.Text = DataGridView1.CurrentRow.Cells(11).Value.ToString
frmEdit.DateTimePicker1.Value = DataGridView1.CurrentRow.Cells(12).Value.ToString
frmEdit.DateTimePicker2.Value = DataGridView1.CurrentRow.Cells(13).Value.ToString
If DataGridView1.CurrentRow.Cells(14).Value.ToString = "Y" Then
frmEdit.rbYes.Checked = True
ElseIf DataGridView1.CurrentRow.Cells(14).Value.ToString = "N" Then
frmEdit.rbNo.Checked = True
End If
frmEdit.cbStatus.Text = DataGridView1.CurrentRow.Cells(15).Value.ToString
frmEdit.txtNote.Text = DataGridView1.CurrentRow.Cells(16).Value.ToString
frmEdit.lblMody.Text = tslblLoginAs.Text
frmEdit.ShowDialog()
load_data()
End Sub
This is second form's code for connecting to the database table for the combobox:
Private Sub Edit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim frmMasterList As New MasterStaff
Dim poscmd As New SqlCommand("SELECT * from MasterPositionList", conn)
Dim posadapt As New SqlDataAdapter(poscmd)
Dim postable As New DataTable
posadapt.Fill(postable)
cbPosition.DataSource = postable
cbPosition.DisplayMember = "PositionName"
Dim depcmd As New SqlCommand("SELECT * from MasterDepartmentList", conn)
Dim depadapt As New SqlDataAdapter(depcmd)
Dim deptable As New DataTable
depadapt.Fill(deptable)
cbDepartment.DataSource = deptable
cbDepartment.DisplayMember = "DeparmentName"
End Sub
The form load event fires too late to populate the combobox. The event is raised almost immediately when you create the form instance in the DataGridView1_CellDoubleClick() method, but the event handler can't actually run until control is returned to the messaging loop, and there's no chance for that to happen until the frmEdit.ShowDialog() line, which is after you have set the combobox values. Therefore the Load event runs after you have populated your desired value and will overwrite that work.
To fix this, move that Load code to the constructor, just after the InitializeComponent() method.
Additionally, since you want to select from the items provided by the database you should look at using the SelectedItem or SelectedValue property, instead of the Text property.
Finally, it's really poor practice to reuse the same connection object throughout an application or form. Yes, database connections are expensive objects to create and manage, but the ADO.Net library already handles this for you. The SqlConnection object you work with in code is a light-weight wrapper over a pool of the more-expensive actual raw connections. When you try to reuse one SqlConnection, you gain efficiency in the cheap thing while losing efficiency in the more expensive thing.
Instead, create (and promptly Dispose()!) a new SqlConnection object every time you need to use the database, and think about reducing connections by reducing round-trips to the database. In this case, you can combine the two SELECT statements into a single string and fill two DataTables in the same database trip:
Private Sub New ' Replaces the current Edit_Load() method
InitializeComponent()
Dim results As New DataSet
'Using block will make sure the connection is closed, **even if an exception is thrown**
' Do NOT(!) try to reuse the connection. Only reuse the connection string.
Using conn As New SqlConnection(connString), _
' Two SELECT queries in one string
cmd As New SqlCommand("SELECT * from MasterPositionList;SELECT * from MasterDepartmentList", conn), _
da As New DataAdapter(cmd)
da.Fill(results)
End Using 'Dispose the database objects as quickly as possible
cbPosition.DisplayMember = "PositionName"
cbDepartment.DisplayMember = "DeparmentName"
cbPosition.DataSource = results.Tables(0) 'Filled two tables in one database call
cbDepartment.DataSource = results.Tables(1)
End Sub
I am wondering why you need a separate form when you could edit the data directly in the DGV. When you think of it, all the data you're trying to edit is already found in the DGV (or should exist in its datasource). You can even have combo boxes inside the DGV, with their own bound datatables. Here is an example that shows how it could be done.
In Edit_Load there is unnecessary repetition. You load the same dataset twice. You could reuse it or even load it at startup and keep it in cache if it's not changing during application runtime.
Plus, rather than fetch values from the DGV, it would better to fetch the selected datarow instead. For this you just need the record ID...
There is no need to access UI attributes, use the underlying datatable instead.
You shouldn't be using index numbers. Imagine the mess and potential for bugs if you want to insert columns or move columns. Also, the user probably can reorder columns in the DGV by drag & drop... thus your logic is ruined and the program will not behave like it should.
Anyway, to answer your issue: you've loaded a datatable, now all you have to do is bind it to the combo (which you did). You have used the DataSource and DisplayMember attributes. You could use SelectedValue to preselect a value in the list like this:
With cbPosition
.DisplayMember = "PositionName"
.ValueMember = "PositionName"
.SelectedValue = "The text value that comes from the DGV"
.DataSource = postable
End With
As long as the value from the DGV is present in the datatable this should work.
Again, I think you should simplify your UI. All the data could be edited in-place in the DGV.

datagridview last programmatically changed cell does not get included in changedrows

VB.net app changes values in a datagridview programmatically. The values are all as they should be, but the save routine (dtShipments is the datatable that is the source for the datagridview)
Dim dtChanges As DataTable = dtShipments.getchanges()
If more than one has changed, dtChanges is always missing the last row.
In the routine that changes the cell values, I have tried DatagridView1.EndEdit and DatagridView1.CommitEdit, but the behavior is the same. I even tried adding a SendKeys.Send(vbTab) line, since hitting the tab key when making the changes manually is enough to get all the changes to show up in .GetChanges.
What am I missing?
code per request:
Private Sub btnAssign_Click(sender As Object, e As EventArgs) Handles btnAssign.Click
strModErr = "Form1_btnAssign_Click"
Dim sTruck As String = ""
Try
sTruck = Me.DataGridView2.SelectedCells(0).Value.ToString
For Each row As DataGridViewRow In DataGridView1.SelectedRows
row.Cells("Truck").Value = sTruck
Next
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
Catch ex As Exception
WriteErrorToLog(Err.Number, strModErr + " - " + Err.Description)
End Try
End Sub
Private Function SaveChanges() As Boolean
strModErr = "Form1_SaveChanges"
Dim Conn As New SqlConnection(My.Settings.SQLConnectionString)
Dim sSQL As String = "UPDATE fs_Shipments SET Truck = #Truck, Stop = #Stop WHERE SalesOrder = #SO"
Dim cmd As New SqlCommand(sSQL, Conn)
Dim sSO, sTruck As String
Dim iStop As Integer = 0
Try
DataGridView1.EndEdit()
DataGridView1.ClearSelection()
Dim dtChanges As DataTable = dtShipments.getchanges() 'DataRowState.Modified
If Not dtChanges Is Nothing Then
Conn.Open()
For Each row As DataRow In dtChanges.Rows
sSO = row("SalesOrder").ToString
sTruck = row("Truck").ToString
iStop = CInt(row("Stop").ToString)
With cmd.Parameters
.Clear()
.AddWithValue("#SO", sSO)
.AddWithValue("#Truck", sTruck)
.AddWithValue("#Stop", iStop)
End With
cmd.ExecuteNonQuery()
Next
End If
Return True
Catch ex As Exception
WriteErrorToLog(Err.Number, strModErr + " - " + Err.Description)
Return False
End Try
End Function
I am not exactly 100% sure why this happens. The problem appears to be specific to when the user “selects” the cells in the first grid, and then calls the SaveChanges code “BEFORE” the user has made another selection in the first grid. In other words, if the user “selects” the rows to “assign” the truck to in grid 1, then, “AFTER” the “selected” cells have been filled with the selected truck, THEN, the user selects some other cell in grid 1, THEN calls the save changes code. In that case the code works as expected.
All my attempts at committing the changes, either failed or introduced other issues. I am confident a lot of this has to do with the grids SelectedRows collection. IMHO, this looks like a risky way to set the cell values, I would think a more user-friendly approach may be to add a check box on each row and assign the truck values to the rows that are checked. But this is an opinion.
Anyway, after multiple attempts, the solution I came up with only further demonstrates why using a BindingSource is useful in many ways. In this case, it appears the DataTable is not getting updated with the last cell change. Again, I am not sure “why” this is, however since it appears to work using a BindingSource, I can only assume it has something to do with the DataTable itself. In other words, before the “Save” code is executed, we could call the tables AcceptChanges method, but then we would lose those changes. So that is not an option.
To help, below is a full (no-fluff) example. In the future, I highly recommend you pull out the parts of the code that do NOT pertain to the question. Example, all the code that saves the changes to the DB is superfluous in relation to the question… so remove it. The more unnecessary code you add to your question only increases the number of SO users that will “ignore” the question. If you post minimal, complete and working code that reproduces the problem so that users can simply copy and paste without having to add addition code or remove unnecessary code will increase you chances of getting a good answer. Just a heads up for the future.
The solution below simply adds a BindingSource. The BindingSource’s DataSource is the DataTable dtShipments then the BindingSource is used a DataSource to DataGridView1. Then in the SaveChanges method, “before” the code calls the dtShipment.GetChanges() method, we will call the BindingSources.ResetBinding() method which should complete the edits to the underlying data source, in this case the DataTable dtShipments.
If you create a new VS-VB winforms solution, drop two (2) grids and two (2) buttons onto the form as shown below, then change the button names to “btnAssign” and “btnApplyChanges.” The assign button will add the selected truck in grid two to the selected rows in grid one. The apply changes button simply resets the binding source and displays a message box with the number of rows that were changed in the dtShipments DataTable. It should be noted, that the code calls the dtShipments.AcceptChanges() method to clear the changes. Otherwise, the code will update changes that have already been made.
Dim dtShipments As DataTable
Dim dtTrucks As DataTable
Dim shipBS As BindingSource
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dtShipments = GetShipmentsDT()
shipBS = New BindingSource()
shipBS.DataSource = dtShipments
dtTrucks = GetTrucksDT()
dtShipments.AcceptChanges()
DataGridView1.DataSource = shipBS
DataGridView2.DataSource = dtTrucks
End Sub
Private Function GetShipmentsDT() As DataTable
Dim dt = New DataTable()
dt.Columns.Add("ID", GetType(String))
dt.Columns.Add("Truck", GetType(String))
dt.Rows.Add(1)
dt.Rows.Add(2)
dt.Rows.Add(3)
dt.Rows.Add(4)
Return dt
End Function
Private Function GetTrucksDT() As DataTable
Dim dt = New DataTable()
dt.Columns.Add("Truck", GetType(String))
For index = 1 To 10
dt.Rows.Add("Truck" + index.ToString())
Next
Return dt
End Function
Private Sub btnAssign_Click(sender As Object, e As EventArgs) Handles btnAssign.Click
Dim sTruck = DataGridView2.SelectedCells(0).Value.ToString
'Dim drv As DataRowView
For Each row As DataGridViewRow In DataGridView1.SelectedRows
'drv = row.DataBoundItem
'drv("Truck") = sTruck
row.Cells("Truck").Value = sTruck
Next
'DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
'shipBS.ResetBindings(True)
'DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
End Sub
Private Function SaveChanges() As Boolean
Try
shipBS.ResetBindings(True)
Dim dtChanges As DataTable = dtShipments.GetChanges()
If (dtChanges IsNot Nothing) Then
MessageBox.Show("There are " & dtChanges.Rows.Count & " rows changed in the data table")
' update sql DB
dtShipments.AcceptChanges()
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
Private Sub btnApplyChanges_Click(sender As Object, e As EventArgs) Handles btnApplyChanges.Click
Dim ChangesMade As Boolean
ChangesMade = SaveChanges()
End Sub
Lastly, since you are using VB… I highly recommend that you set the “Strict” option to “ON.” When this option is ON, it will flag possible errors that you may be missing. To do this for all future VB solutions, open VS, close any solutions that may be open, then go to Tools->Options->Projects and Solutions->VB Defaults, then set “Option Strict” to “On.” The default setting is off.
I hope this makes sense and helps.

Datagridview - proper wat of doing Updating/Inserting

I'm doing this for first time and I need some guidance. I have Datagridviews set to It's datasource. Now how do I properly Update or Insert records to DB from It?
My questions:
Currently I dont have any buttons under Datagridviews (like Add/Remove/Update - do I need them without doubt or is It possible to handle all actions without them ? - I don't use TableAdapterManager !)
MERGE statement - can It be used to compare certain Table with Datagridview and perform Update or Insert on same Table?
If doing INSERT or UPDATE manually, what goes first and how to check what must be done ?
I allready have a code for doing both, but It doesn't work as It should, problem is that I have only 1 button for saving data on form - and that button should Insert or Update data in DB from 2 Datagridviews + Databinded Textboxes on form. So basically there are 3 Tables that can be Updated/Inserted on same form - Datagridviews show related data and Databinded Texboxes show master Table record.
Any help much appreciated.
EDIT (here is my complete code - first loading data into form and Datagrid, then code for Btn_Save):
Imports System.Data
Imports Oracle.DataAccess.Client ' ODP.NET Oracle managed provider
Imports Oracle.DataAccess.Types
Imports System.IO
Imports System
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class Form2
Private da, da1 As OracleDataAdapter
Private cb, cb1 As OracleCommandBuilder
Private ds, ds1 As DataSet
Public OpenedForm1 As Form1 'required for obtaining record ID - this form opens when user double clicks on datagridview record
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BtnSave.Enabled = False 'for eliminating errors when using dataset Update (Oracle recommendation)
Dim SQL1 As String = "SELECT * from TABLE1 WHERE ID_Table1=" & OpenedForm1.DataGridView1.CurrentRow.Cells(0).Value.ToString
Dim DGV1_SQL As String = "SELECT ID_TABLE2, ID_TABLE1, Name, Surname, WHERE ID_TABLE1=" & OpenedForm1.DataGridView1.CurrentRow.Cells(0).Value.ToString
Dim DGV2_SQL As String = "SELECT TABLE3.SERIAL, TABLE3.MODEL," _
& " TABLE3.TYPE FROM TABLE3 INNER JOIN (TABLE1 INNER JOIN TABLE1_TABLE3 ON TABLE1.ID_Table1=TABLE1_TABLE3.ID_Table1_FK) ON " _
& "TABLE3.ID_Table3=TABLE1_TABLE3.ID_Table3_FK WHERE TABLE1_TABLE3.ID_TABLE1_FKK=" & Openedform1.DataGridView1.CurrentRow.Cells(0).Value.ToString
Try
Oracleconn()
'Then I do all DB queries and display results on form
'For SQL1 Databind all textboxes – this is a master record on form
'For DGV2_SQL and DGV2_SQL fill datasets and set Datagrids to datasource
'I'm also hiding all primary key fields and bounding datagrids to Binding sources to enable Binding navigators under them.
End Sub
Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
'First I assign some variables for Oracle parameters, such as dealing with Null Date values
Oracleconn() 'My connection to DB
Using cmd As OracleCommand = New OracleCommand()
cmd.Connection = Oracleconn()
cmd.Parameters.Clear()
'Adding a lot of paramters here for master record like this...
cmd.Parameters.Add(New OracleParameter("ID", TxtID.Text))
))
'Only Update for master record – Textboxes on form – works just fine
cmd.CommandText = "UPDATE TABLE1" _
& " SET ID_TABLE1= : id .etc
If Not (TxtSerial.Text = "" Or TxtInventar.Text = "11111" Or TxtInventar.TextLength < 9) Then
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
'Then checking 1st datagridview for data in It
For Each row As DataGridViewRow In DGV1.Rows
If row.Cells(1).Value <> Nothing Then
'Adding parameters again
'Then my attempt for doing update or Insert with MERGE – doesn't work
cmd.CommandText = "MERGE INTO TABLE2 v" _
& "USING (SELECT * FROM TABLE2 WHERE ID_TABLE2='" & row.Cells(1).Value & "') u" _
& " ON u.ID_TABLE2" _
& " WHEN MATCHED THEN UPDATE SET all fields except ID's " _
' & " WHEN NOT MATCHED BY v" _
' & " THEN INSERT... all fields" _
' & " VALUES.... from parameters"
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
'This was used before, but ofcourse It only updates
da.Update(ds.Tables(0))
BtnSave.Enabled = True
Else
MsgBox("You cannot save without 1st field empty !")
Exit For
End If
Next
'Then check for next Datagrid – this one is hard, It's a joined Table(entitity) from Table1 and Table3, with showing data from that joined Table too
For Each row As DataGridViewRow In DGV2.Rows
'Adding parameters and just performing update – didn't start the Insert so far
MsgBox("Saved.", MsgBoxStyle.Information, "Editing records")
'Refresh Datagridview in Form1 - which is also opened
OpenedForm1.BtnSearch()
Else
MsgBox("1st field is required to be filled If you want to save.", MsgBoxStyle.Exclamation, "Editing records")
End If
End Using
OracleClose() 'close my connection
End Sub
You basically need to do inserts first, then updates, then deletes. You must insert parents before children and, unless your foreign keys cascade deletes, delete children before parents. For updates, it doesn't matter the order. E.g.
Dim parentAdapter As SqlDataAdapter
Dim childAdapter As SqlDataAdapter
Dim data As DataSet
Dim parentTable As DataTable
Dim childTable As DataTable
'...
Dim parentInserts = parentTable.GetChanges(DataRowState.Added)
Dim parentUpdates = parentTable.GetChanges(DataRowState.Modified)
Dim parentDeletes = parentTable.GetChanges(DataRowState.Deleted)
Dim childInserts = childTable.GetChanges(DataRowState.Added)
Dim childUpdates = childTable.GetChanges(DataRowState.Modified)
Dim childDeletes = childTable.GetChanges(DataRowState.Deleted)
If parentInserts IsNot Nothing Then
parentAdapter.Update(parentInserts)
End If
If childInserts IsNot Nothing Then
childAdapter.Update(childInserts)
End If
If parentUpdates IsNot Nothing Then
parentAdapter.Update(parentUpdates)
End If
If childUpdates IsNot Nothing Then
childAdapter.Update(childUpdates)
End If
If childDeletes IsNot Nothing Then
childAdapter.Update(childDeletes)
End If
If parentDeletes IsNot Nothing Then
parentAdapter.Update(parentDeletes)
End If
data.AcceptChanges()
Let Me answer you to the best and honest way as I can because honestly I did that before.
I will answer based on what I used Prog. Lang. and Database and Luckily VB.Net is my Language and MySQL is the database.
My Answers: (Order by your question)
1.Your asking if you need them? For me Yes! because i did that, Think of a form with a DatagridView (Populated with Data) and 3 Buttons (Add,Update,Delete)
Button: Add will save all your datagridview data in table. You see some link or tutorials here
Button: Edit will update specific data based on what you selected you can see it here. What I did is transfer them to textboxes and do the update.
Button: Delete will delete the data based on your selected row actully the link from button update will be your guide you will just edit it and the Delete Query
2.10000% YES! see this the output of that is to put color in datagridview if both of them are the same. (Sounds exiting? Love it :D)
3.Doing manualy would be hard for me so my tip here is why dont you edit your datagridview then do the Update Command Datagridview is editable but Pls provide atleast 1 column that will not be updated because it is the basis of your where clause
So there you go I said everything I know and it will depend on you on what you should follow so good luck and happy coding
Remember : Theres no wrong in coding One Output Tons of ways to execute

VB.Net affect changes to a table

I am using a datagridview to display table data and changing values of a particular cell. Depending on requirement I may need to change such values for more than one row.
I am trying to use datagridview1.CellValueChanged to populate a Dataset (i.e. create a collection of changes made) and subsequently saving the changes by clicking on a command button.
My problem is that though for each change, the sub is being called ONLY the last change is being saved. I was thinking of using the Dataset to store multiple records where the values are changed and then SAVE all the rows in the Dataset in the database table (using Update).
Could there be some solution to my predicament.
PS. Before trying this (ADO.net dataset) I was updating a temporary table and then using that I was updating the database.
Grateful for a solution please.
Code:::
Private Sub dGridVwCreaCode_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dGridVwCreaCode.CellValueChanged
Dim qryStr_CodeShtText_Changed As String
Dim var_CodeID_Changed As Long
var_CodeID_Changed = dGridVwCreaCode(e.ColumnIndex - 2, e.RowIndex).Value
qryStr_CodeShtText_Changed = "SELECT Code_ID, Code, Code_Descrip FROM Code_SAP " & _
"WHERE (Code_SAP.Code_ID = " & var_CodeID_Changed & ")"
var_CodeShtText_Changed = dGridVwCreaCode(e.ColumnIndex, e.RowIndex).Value.ToString
If Not CatGenieConnPublic.State = ConnectionState.Open Then
CatGenieConnPublic.Open()
End If
da_CodeShtText_Changed = New OleDb.OleDbDataAdapter(qryStr_CodeShtText_Changed, CatGenieConnPublic)
da_CodeShtText_Changed.Fill(ds_CodeShtText_Changed, "Code_SAP")
cb_CodeShtText_changed = New OleDb.OleDbCommandBuilder(da_CodeShtText_Changed)
ds_CodeShtText_Changed.Tables("Code_SAP").Rows(1).Item("Code_Descrip") = var_CodeShtText_Changed
To save the changes (following sub being called from a Button_Click):
Private Sub Save_Changed_CodeShtText()
da_CodeShtText_Changed.Update(ds_CodeShtText_Changed, "Code_SAP")
MsgBox("Changes saved to database....", vbOKOnly + vbInformation)
If CatGenieConnPublic.State = ConnectionState.Open Then
CatGenieConnPublic.Close()
End If
'SET BOOLEAN TO FALSE AS CHANGED VALUES HAVE BEEN SAVED
bool_CellVal_HasChanged = False
End Sub
PS. Somehow I am not able to place all the code lines together, pl pardon me.
What I was missing out on was incrementing the "row" count in the code line:
ds_CodeShtText_Changed.Tables("Code_SAP").Rows(rowNum_Increment - 1).Item("Code_Descrip") = var_CodeShtText_Changed
So every time the user changes data in the particular cell, rows number in incremented by "1" and is collected in the dataset.

Rowstate remains always unchanged even if data changes

I have a datagrid bound to Oracle database. I would like to update my fields through the gridview. I used Update method which was not successful. After advanced diagnose I came up with the following observations when executing this code.
Private Sub MainGridView_ColumnChanged(ByVal Sender As Object, ByVal e As DataColumnChangeEventArgs) Handles DataTable.ColumnChanged
e.Row.AcceptChanges()
e.Row.EndEdit()
DataTable.AcceptChanges()
BindingSource.EndEdit()
End Sub
When I change a row, the value changes in memory. It's checked using break points and Watchs ( e.Row.Item("Field") has a different value )
e.Row.RowState remains Unchanged in the watch in all the steps of the excution.
Here is the code for binding the data to the database:
Public Sub FillForm()
SQL = "SELECT * FROM ARCHITECT.ARCH_TASKS"
Command = New OracleCommand(SQL, Connection)
DataAdapter = New OracleDataAdapter(Command)
DataSet.Tables.Add(DataTable)
DataAdapter.Fill(DataTable)
BindingSource.DataMember = "Table1"
BindingSource.DataSource = DataSet
Me.GridControl1.DataSource = BindingSource
End Sub
Here is a video preview Preview
Is there anything else I should take into consideration ?
Appreciate your help.