locked
on delete particuler row i get the Exception RRS feed

  • Question

  • Dear sir I get the table data in datagridview and then select the paticuler cell and update it then working is easily go on .
    But when i delete the particuler row then then i got the exception from wr(row index of next focusing row)
        In my project the  The focus on the next row is necessary  and select the whole row delete is also necessary.
    I want some guidance for handlind this exception
    My code is below


    'Imports msdatasrc
    Imports System.Data.OleDb


    Public Class Form1


        Dim connetionString As String


        Dim connection As OleDbConnection


        Dim adapter As OleDbDataAdapter


        Dim cmdBuilder As OleDbCommandBuilder


        Dim ds As New DataSet


        Dim changes As DataSet


        Dim sql As String


        Dim i As Int32


        'Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        '    Try


        '        cmdBuilder = New OleDbCommandBuilder(adapter)


        '        changes = ds.GetChanges()


        '        If changes IsNot Nothing Then


        '            adapter.Update(changes)


        '        End If


        '        MsgBox("Changes Done")


        '    Catch ex As Exception


        '        MsgBox(ex.ToString)


        '    End Try
        'End Sub
















        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


            connetionString = "Provider=SQLOLEDB;Data Source=I7;Integrated Security=SSPI;Initial Catalog=BGBC2012"


            connection = New OleDbConnection(connetionString)


            sql = "select * from st"
            Try








                adapter = New OleDbDataAdapter(sql, connection)


                adapter.Fill(ds)






                DataGridView1.DataSource = ds.Tables(0)




            Catch ex As Exception


                MsgBox(ex.ToString)


            End Try


        End Sub


       












        


       


        Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
            Try
                Dim wr As Integer
                Dim wc As Integer
                cmdBuilder = New OleDbCommandBuilder(adapter)


                changes = ds.GetChanges()
                
                If changes IsNot Nothing Then


                   
                   
                    wr = DataGridView1.CurrentRow.Index                   //From this line we get the exception
                    wc = DataGridView1.CurrentCell.ColumnIndex




                    adapter.Update(changes)
                    changes.AcceptChanges()
                    ds.AcceptChanges()
                    DataGridView1.CurrentCell = DataGridView1.Item(wc, wr + 1)
                    adapter = New OleDbDataAdapter(sql, connection)
                    adapter.Fill(ds)
                    DataGridView1.DataSource = ds.Tables(0)
                    'MsgBox("Changes Done")
                End If






            Catch ex As Exception


                MsgBox(ex.ToString)


            End Try


        End Sub
    End Class

    Thursday, July 26, 2012 6:53 AM

Answers

  • thanx sir,

    I got the solution of this problem

     if Is currentrow.index nothing  then

    code 

    end 

    Monday, July 30, 2012 8:34 AM

All replies

  • You have not shared the Code For Delete Operation. So share how are you deleting the row.


    Lingaraj Mishra

    • Marked as answer by Praful Dangre Monday, July 30, 2012 8:35 AM
    • Unmarked as answer by Praful Dangre Monday, July 30, 2012 8:35 AM
    Thursday, July 26, 2012 12:59 PM
  • Hi Praful,

    Welcome to the MSDN Forum.

    As Lingaraj said, please show me your delete operation related code and the exactly exception messages. Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 27, 2012 7:22 AM
    Moderator
  • thanx sir,

    I got the solution of this problem

     if Is currentrow.index nothing  then

    code 

    end 

    Monday, July 30, 2012 8:34 AM
  • thanx sir

    Monday, July 30, 2012 8:34 AM
  • thanx sir

    Hi Praful,

    So what is the solution? Is that you deleted one?

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 30, 2012 9:03 AM
    Moderator