none
Coding for delete datagridview selected Row RRS feed

  • Question

  • I have following coding for insert record.

    What coding i need for deletedatagridview selected rows from database and datagridview.

    Public Class Form1

        Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
            Dim conn As New SqlServerCe.SqlCeConnection("Data Source=|DataDirectory|\CalDatabase.sdf")
            Dim cmd As New SqlServerCe.SqlCeCommand
            Try
                cmd.CommandText = "INSERT INTO tbl_Invoice (Month, Rate, Qty, MiscCharges, Total) VALUES        (@Month, @Rate, @Qty, @MiscCharges, @Total)"
                cmd.CommandType = CommandType.Text
                cmd.Connection = conn
                With cmd.Parameters
                    .AddWithValue("@Month", txtMonth.Text).DbType = DbType.DateTime
                    .AddWithValue("@Rate", txtRate.Text)
                    .AddWithValue("@Qty", txtQty.Text)
                    .AddWithValue("@MiscCharges", txtMiscCharges.Text)
                    .AddWithValue("@Total", txtTotal.Text)
                End With

                txtMonth.Clear()
                txtRate.Clear()
                txtQty.Clear()
                txtMiscCharges.Clear()
                txtTotal.Clear()
                txtMonth.Focus()

                conn.Open()
                cmd.ExecuteNonQuery()
                Me.Tbl_InvoiceTableAdapter.Fill(Me.Ds_Invoice.tbl_Invoice)

            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                conn.Close()
                cmd.Parameters.Clear()
            End Try

        End Sub

    Kindly help me i am stuck in delete coding


    • Edited by iffi_nice Saturday, May 25, 2013 4:32 AM
    Saturday, May 25, 2013 4:32 AM

Answers