Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of Lynchie435
Lynchie435

VB.NET DataGridView Button Not Removing Current Row
Afternoon,

I have a DataGridView with records in it. I have added an Unbound column to the end of the DataSet that deletes the record and updates a SQL table.

I am able to click the delete button and it remove my DataGridView Row, however the SQL inserts the SQL for the record below the one I have selected the delete on.

My code is below is anyone able to explain this behaviour to me?

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        'Declare Variables
        Dim strSQL As String
        Dim cmd As SqlCommand
        Dim i As Integer
        'Dim msg As String = _
        'String.Format("Editing Cell at ({0}, {1})", _
        'e.ColumnIndex, e.RowIndex)

        i = e.ColumnIndex

        If i <> 8 Then

            DataGridView1.Columns(i).ReadOnly = True

        Else

            LiveTableBindingSource.RemoveAt(e.RowIndex)

            strSQL = "INSERT INTO [MyDB].[dbo].[Database]" & _
                    " VALUES ('" & DataGridView1.Rows(e.RowIndex).Cells(0).Value() & "','" & DataGridView1.Rows(e.RowIndex).Cells(1).Value() & "','" & DataGridView1.Rows(e.RowIndex).Cells(2).Value() & "','" & DataGridView1.Rows(e.RowIndex).Cells(3).Value() & "','" & DataGridView1.Rows(e.RowIndex).Cells(4).Value() & "','Removed','" & Date.Now.ToString & "','" & DataGridView1.Rows(e.RowIndex).Cells(7).Value() & "')"

            conn.Open()
            cmd = New SqlCommand(strSQL, conn)
            cmd.ExecuteNonQuery()
            conn.Close()

            Me.History_Table_TableAdapter.Fill(Me.FreshSystemsDataSet.History_Table)

        End If

    End Sub

Open in new window

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of UnifiedISUnifiedIS

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Lynchie435Lynchie435

ASKER

Had every inkling it was something basic but I had been coding all day that I had overlooked it.

Many heads and all that.

Cheers mate much appreciated.

James

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.