Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys.

I'm using

*Visual Studio 2012
*MS Access 2013
*ADO.Net

I set my DataGridView properties in their proper behavior so that the User won't accidentally mess the DataGridView Display

ReadOnly = True
AllowUserToAddRows = False
AllowUsertoDeleteRows = True
AllowUserToOrderColumn = False
AllowUserToResizeColumns = False
AllowUserToResizeRows = False
RowHeadersWidthSizeMoe = DisableResizing
SelectionMode = FullRowSelect

These are my declared SQL Statements

For View Button
VB.NET
Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
      ConnectDB()

      Dim Command As New OleDbCommand("SELECT * FROM Reservations ORDER BY ID", conn)
      Dim adapter As New OleDbDataAdapter
      Dim dt As New DataTable
      adapter.SelectCommand = Command
      adapter.Fill(dt)
      dgvDisplay.DataSource = dt
      dgvSizes()
      adapter.Dispose()
      Command.Dispose()
      conn.Close()
  End Sub


For Save Button:

C#
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

     If cboPlace.SelectedItem = "" Then
         MessageBox.Show("Please Pick Place")
         Exit Sub
     ElseIf cboFacility.SelectedItem = "" Then
         MessageBox.Show("Please choose Facility")
         Exit Sub
     ElseIf txtRequestor.Text = "" Then
         MessageBox.Show("Please enter the Requestor's Name")
         Exit Sub
     End If

     ConnectDB()

     Dim Command As New OleDbCommand("INSERT INTO Reservations ([Place],[Facility],[Date Reserved],[Time Start],[Time End],[Requestor],[Price],[Note])" & _
                                     "VALUES (@place, @facility, @datereserved, @timestart, @timeend, @requestor, @price, @note)", conn)

     Command.Parameters.AddWithValue("@place", cboPlace.SelectedItem)
     Command.Parameters.AddWithValue("@facility", cboFacility.SelectedItem)
     Command.Parameters.AddWithValue("@datereserved", datPick.Value.Date)
     Command.Parameters.AddWithValue("@timestart", timeStart.Value.ToString("hh:mm tt"))
     Command.Parameters.AddWithValue("@timeend", timeEnd.Value.ToString("hh:mm tt"))
     Command.Parameters.AddWithValue("@requestor", txtRequestor.Text)
     Command.Parameters.AddWithValue("@price", x.ToString("c"))
     Command.Parameters.AddWithValue("@note", txtNote.Text)

     Command.Connection = conn
     Command.ExecuteNonQuery()
     MsgBox("User Successfully Save!")
     Command.Dispose()
     conn.Close()
     Clear()
     btnView.PerformClick()


End Sub

I want to delete the specific highlighted rows by clicking the ID column, just one full row that has values on every row.

This is my code, i want you guys to add some specific code to link it to the ID value:

VB.NET
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

        ConnectDB()
        Command = New OleDbCommand("DELETE FROM Reservations where ID=", conn)
        Command.ExecuteNonQuery()
        MsgBox("User Successfully delete!")
        Command.Dispose()
        conn.Close()
        btnView.PerformClick()
    End Sub


What I have tried:

I did link the ID = Autonumber value to its Label ID text and use UPDATE Statement but its only deleting the values from the top and not the desired highlighted rows.

For e.g.

Click Delete button

<execute code="">

What happens is ?
ID = 1 was deleted not the chosen ID = 5, the Highlighted row.

Please help me cause I'm looking for a solution.

Do I need to use INSERT , or UPDATE Statements in my Save button?

Please answer ASAP, Many kudos those who would answer my problem . Advance Thank you :)
Posted
Updated 10-Aug-16 0:16am

try this,

if lable is not find,first find it.

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

ConnectDB()
int id=lblid.text;
Command = New OleDbCommand("DELETE FROM Reservations where ID=id", conn)
Command.ExecuteNonQuery()
MsgBox("User Successfully delete!")
Command.Dispose()
conn.Close()
btnView.PerformClick()

End Sub
 
Share this answer
 
Ok tried but I want to delete the specific highlighted rows by clicking the ID column, just one full row that has values on every row.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900