This is a migrated thread and some comments may be shown as answers.

Edit GridView bound to MS SQL Server Dataset Error

5 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 08 Apr 2014, 02:54 PM
I am having some issues trying to edit rows in a GridView that is bound to a MS SQL Server dataset.   I created a new test project to make sure it wasn't something else in my code somewhere that is causing the issue.  The test project only has a form with 1 control on it (rad gridview)  I created a dataset in VS Studio 2012 and bound the gridview to it.  Whenever  I attempt to update a field in the gridview I am getting the error message: DataTable internal index is corrupted: '5'.  I did some research and this error can happen when you are accessing a datatable from multiple threads - which I am not.  I have another application where I use the same code with a local MS Access database and the code works perfectly.  Here is the code in my test application:

Public Class Form1
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'IT_InventoryDataSet.InventoryRun' table. You can move, or remove it, as needed.
        Me.InventoryRunTableAdapter.Fill(Me.IT_InventoryDataSet.InventoryRun)
 
    End Sub
 
    Private Sub InventoryRunBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles InventoryRunBindingSource.CurrentChanged
 
    End Sub
 
    Private Sub InventoryRunBindingSource_ListChanged(sender As Object, e As System.ComponentModel.ListChangedEventArgs) Handles InventoryRunBindingSource.ListChanged
 
        If e.ListChangedType = System.ComponentModel.ListChangedType.ItemChanged Then
 
            Me.InventoryRunTableAdapter.Update(Me.IT_InventoryDataSet.InventoryRun)
 
        End If
    End Sub
End Class

5 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 11 Apr 2014, 11:50 AM
Hello Andrew,

Thank you for contacting us.

I have reviewed your code and it seems perfectly fine. In order to reproduce this locally I would like to kindly ask you to provide me with a sample project and the database which you are using for your tests. This will allow me to properly investigate this case and provide you with adequate support.

Looking forward to your response.

Regards,
George
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Andrew
Top achievements
Rank 1
answered on 11 Apr 2014, 01:16 PM
Hi George,

I have upgraded the project to VS 2013 and the latest version of the Telerik Winforms controls and the problem persists.  I am attaching the sample project and the SQL server database files.  It is from SQL Server 2005.  

Apparently it is not letting me attach .zip files to this post or attachments over 2 Mb.  Here is a drop box link:

https://www.dropbox.com/sh/cd9cmu3fvskw1qu/UD4afVh1UW
0
George
Telerik team
answered on 16 Apr 2014, 08:11 AM
Hi Andrew,

Thank you for replying.

I was easily able to bind RadGridView to your database. You can use this guide to bind RadGridView and this guide to gain knowledge of how to update your database. My code is as follows:
private DataRow lastEditRow = null;
void inventoryBindingSource_CurrentChanged(object sender, EventArgs e)
{
    DataRow dataRow = ((DataRowView)((BindingSource)sender).Current).Row;
    if (lastEditRow != null && lastEditRow.RowState == DataRowState.Modified)
    {
        this.inventoryTableAdapter.Update(lastEditRow);
    }
 
    lastEditRow = dataRow;
}

You can also download the modified project which is attached below.

Let me know if you have further questions.

Regards,
George
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Andrew
Top achievements
Rank 1
answered on 16 Apr 2014, 01:25 PM
Thank you for your help - I did however find 2 bugs with the code in the guide when it come to editing rows via ADO.net.  I used your code and it does work, however if you only have 1 row in the table or your are editing the last row in the gridview and you hit enter after making your edits the CurrentChanged event never fires and thus your edits are not saved.  
0
Accepted
Dimitar
Telerik team
answered on 18 Apr 2014, 10:35 AM
Hello Andrew,

Thank you for writing back.

To cover the described cases you can use one of the events designed to changes tracking in RadGridView. Detailed information about this is available in the following article: Tracking changes in RadGridView.

If you have any questions, please do not hesitate to contact us.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
George
Telerik team
Andrew
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or