locked
delete the whole rows RRS feed

  • Question

  • Hi all,

    I can update using this code but the problem is that when I wanted to delete the whole rows using this code it code not. Could anyone help me?
    Here is the code that I am using:
        Dim myDA As OleDbDataAdapter
        Dim myDataSet As DataSet
    
        Private Sub ViewCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim con As OleDbConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = G:\MajorProjectFile\ProjectSample\database\User.mdb")
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT CustID,custName,Address,Positions,CompanyName,Email,Telephone,Industry FROM Customer", con)
            con.Open()
            myDA = New OleDbDataAdapter(cmd)
            'Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object  
            Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)
            myDataSet = New DataSet()
            myDA.Fill(myDataSet, "Customer")
            DataGridView1.DataSource = myDataSet.Tables("Customer").DefaultView
            con.Close()
            con = Nothing
    
        End Sub
     
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            Me.Validate()
            Me.myDA.Update(Me.myDataSet.Tables("Customer"))
            Me.myDataSet.AcceptChanges()
    
        End Sub
    Thanks

    Regards
    LiL_is
    Thursday, October 8, 2009 1:26 PM

Answers

  •  

    Using novo As New OleDbConnection(StrCnn)

     

    Dim levi As String = "lucy"

     

    Dim apagar As New OleDbCommand("Delete * From STUDENT where FirstName=@FirstName", novo)

    apagar.Parameters.AddWithValue(

    "@FirstName", levi)

     

    'novo.Open()

     

    Dim isaa As Integer = apagar.ExecuteNonQuery

    MsgBox(

    "Deleted")

     

    End Using


    Don't judge me, just Upgrade me. Thanks!
    • Marked as answer by Jeff Shan Monday, October 12, 2009 8:52 AM
    Thursday, October 8, 2009 8:30 PM