Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

the code below is my delete button, but the problem is i dont know how to make i

ID: 3775994 • Letter: T

Question

the code below is my delete button, but the problem is i dont know how to make it specific for the exact row i want to delete, because when i run it works but it would delete all rows that has the 'New York' and i dont want that i just want it to delete the specific one i want i clicked on from the database. How to modify it ?

string connetionString = null;
            OleDbConnection connection;
            OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
            string sql = null;
            connetionString = @"Provider = Microsoft.ACE.OLEDB.12.0; Data Source=C:UserssereneDesktopsamb - CopysambPublic.accdb; Persist Security Info = False;";
            connection = new OleDbConnection(connetionString);
            sql = "delete from Incidents where Location = 'New York'";
            try
            {
                connection.Open();
                oledbAdapter.DeleteCommand = connection.CreateCommand();
                oledbAdapter.DeleteCommand.CommandText = sql;
                oledbAdapter.DeleteCommand.ExecuteNonQuery();
                MessageBox.Show("Row(s) Deleted !! ");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

Explanation / Answer

hi. Since you are using 'delete from Incidents where Location = 'New York'' query, all of the records whose location is New York are deleted.
If you are selecting the record from the database then how can you delete using the java code.?
You need to fetch the data from the database and present it in the JTable in the user interface in your application. You can use vector datastructure for retreiveing & storing the data from the database.
Now, when the user selects any particular record, you can get the record number or id of the selected record in java code.
now, you can delete that particular record by adding it to the delete query.
for instance, the record that is selected has 'incidentID' = 10, then you can modify your query to

String incidentID= getselectedRecord();
sql = "delete from Incidents where Location = 'New York' "+"and incidentID=' "+incidentID+" ' ";

feel free if you have any doubt. Post your question with exact details. That will help experts to answer your query well.