I am currently creating an window application connected with a Microsoft Access database to perform CRUD operation for the business related to education
One of the workflow is to search the keyword and perform CRUD operation in the DataGrid View At first , I am trying to display the datagrid view of the record ( such as students , time to take course, what course...e.t.c.) with respect to the receipt number
The application logic is to get the receipt number in the datagrid View and perform delete operation
So my question is
How to get the value of the receipt number column in the selected row of the datagrid view?
There are OleCommands and OleDataAdapter to perform the CRUD operation. Which method shall I use ?
The following is the code for the delete operation
public void delete_course_transaction(string receipt_no)
{
OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
try
{
using (OleDbConnection connection = new OleDbConnection(connectionDBString))
{
string sql = "delete from COURSE_TAKE where COURSE_TAKE.RECEIPT_NO = '" + receipt_no + "'";
connection.Open();
oledbAdapter.DeleteCommand = connection.CreateCommand();
oledbAdapter.DeleteCommand.CommandText = sql;
int rows = oledbAdapter.DeleteCommand.ExecuteNonQuery();
if (rows > 0)
{
MessageBox.Show("Delete Course transaction Success!");
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}