944,044 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 25704
  • VB.NET RSS
Sep 7th, 2005
0

Deleting a Row From A DataGrid

Expand Post »
I have the following two functions. My goal is to highlight a row in a
datagrid and delete a row. Problem arises when I click on the delete button.
Below are two sub routines for DoDelete. Which route should I go with?
I have created stored procedure for deleting the row as well.
Any help would be greatful.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub highLightRow(ByVal sender As Object, ByVal e As MouseEventArgs)
  2.  
  3. Dim pt = New Point(e.X, e.Y)
  4. Dim grd As DataGrid = CType(sender, DataGrid)
  5. Dim hit As DataGrid.HitTestInfo = grd.HitTest(pt)
  6.  
  7.  
  8. If hit.Type = grd.HitTestType.Cell Then
  9. grd.CurrentCell = New DataGridCell(hit.Row, hit.Column)
  10. RowNum = hit.Row
  11. grd.Select(RowNum)
  12.  
  13. PolicyNumber = Convert.ToString(grd.Item(RowNum, 1))
  14. TransCodeOrig = Convert.ToString(grd.Item(RowNum, 2))
  15. TransEffDate = Convert.ToString(grd.Item(RowNum, 3))
  16. ModifiedUID = Convert.ToString(grd.Item(RowNum, 7))
  17. End If
  18. End Sub

Public Sub DoDelete()
        Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember)
        Dim dr As DataRow = CType(bm.Current, DataRowView).Row
        Try
            PolicyNumber = dr(1)
            TransCodeOrig = dr(2)
            TransEffDate = dr(3)
            ModifiedUID = dr(7)
            dr.Delete()
            DsTransOverride1.dbo_stp_SelTransOverrides.Clear()
            SqlDataAdapter1.Fill(DsTransOverride1.dbo_stp_SelTransOverrides)
            ' SqlDataAdapter1.Update(Me.DsTransOverride1, "dbo_stp_SelTransOverrides")
            DsTransOverride1.dbo_stp_SelTransOverrides.AcceptChanges()
            Me.lbNumRec.Text = Me.DsTransOverride1.Tables(0).Rows.Count.ToString()
        Catch exError As Exception
            MessageBox.Show(exError.Message)
        End Try
    End Sub

Public Sub doDelete()
        '  MDI Main Delete record requ3est toolbar button pressed
        'if no records are displayed on the grid exist then exit
        Dim ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("FinSolMainDBConn")
        Dim connfinsol As New System.Data.SqlClient.SqlConnection(ConnectionString)
        Dim myCommand As New SqlCommand("stp_DelTransOverride ", connfinsol)
        myCommand.CommandType = CommandType.StoredProcedure

        'Add Parameters
        ' 1 Policy Number
        myCommand.Parameters.Add("@Policy_Nbr", SqlDbType.VarChar, 7).Value = PolicyNumber

        ' 2 Original Tranaction Override
        myCommand.Parameters.Add("@Trans_CodeOrig", SqlDbType.VarChar, 6).Value = TransCodeOrig

        ' 3 Transaction Effective Date 
        myCommand.Parameters.Add("@Trans_Eff_Date", SqlDbType.DateTime, 8).Value = TransEffDate

        ' 8 Modified UID 
        myCommand.Parameters.Add("@ModifiedUID", SqlDbType.NVarChar, 48).Value = ModifiedUID

        'Open Connection
        Try
            'Open Connection
            connfinsol.Open()
            myCommand.ExecuteNonQuery()
            MsgBox("Data Deleted Successfully !", MsgBoxStyle.Information, Me.Text)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, Me.Text)
        Finally
            If myCommand.Connection.State = ConnectionState.Open Then
                myCommand.Connection.Close()
            End If
        End Try

    End Sub

I am not sure where to go, which DoDelete do go with.
Last edited by Paladine; Sep 8th, 2005 at 1:51 pm. Reason: PLEASE USE CODE BLOCKS!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mcupryk is offline Offline
14 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help on controls in forms
Next Thread in VB.NET Forum Timeline: Need help with a vb.net project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC