2

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

  1. How to get the value of the receipt number column in the selected row of the datagrid view?

  2. 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);
        }
    }

1 Answer 1

2

If I understand correctly :

for your first question you can use this code :

txtName.Text = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString();

and your second question : refer here :http://forums.asp.net/t/706106.aspx/1

Sign up to request clarification or add additional context in comments.

3 Comments

how about returning the name of column in the datagridview when a particular cell is selected
@LoWaiLun use this code : txtName.Text = dataGridView1.Columns[e.ColumnIndex].HeaderText;
@LoWaiLun in dataGridView1_CellClick event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.