0

Im relatively new to c# and im working on a project at my university, which consist in verifying a switchboard, im working in a CRUD right now to edit, create and delete items for one column in a datagridview, so here is my problem.

whenever i edit , insert or delete a row in a column, it doesn´t update the datagridview in real time, so my objective is to, when i change anything in my datagridview with the CRUD system, is has to be displayed in real time.

if anyone can help me, i appreciated it.

private void button6_Click(object sender, EventArgs e)
    {
        string strcon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Verificacao de Quadros Eletricos\Verificação de Quadros Elétricos\DatabaseENG.accdb";
        string comando = @"UPDATE [Norms Table] SET [Drills (according to the norm EN 61439-2)] = @drills WHERE ID=@id";

        using (OleDbConnection con = new OleDbConnection(strcon))
        {
            using (OleDbCommand com = new OleDbCommand(comando, con))
            {
                com.Parameters.Add("@drills", OleDbType.VarChar).Value = textBox5.Text;
                com.Parameters.Add("@id", OleDbType.VarChar).Value = textBox7.Text;

                try
                {
                    con.Open();
                    com.ExecuteNonQuery();
                    MessageBox.Show("Drill succesfully edited");

                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message);
                }
            }
        }
    }

this button is for the edit, this code somehow, when i edit and right away click in a cell it updates the datagridview.

private void button5_Click(object sender, EventArgs e)
{
    string strcon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Verificacao de Quadros Eletricos\Verificação de Quadros Elétricos\DatabaseENG.accdb";
    string comando = @"INSERT INTO [Norms Table] 
                    ([Drills (according to the norm EN 61439-2)])
                    values
                    (@drills)";
        using (OleDbConnection con = new OleDbConnection(strcon))
        {
            using (OleDbCommand com = new OleDbCommand(comando, con))
            {
                com.Parameters.Add("@drills", OleDbType.VarChar).Value = textBox5.Text;

                try
                {
                    con.Open();
                    com.ExecuteNonQuery();
                    MessageBox.Show("Save Well Succeded !");

                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message);
                }
            }
        }

and this one is for the insert that has the problem i mentioned in the beginning.

if i explained myself poorly, im open to explain myself again, as i said, any help can be useful.

Paul T.
  • 4,703
  • 11
  • 25
  • 29
Souz4x
  • 45
  • 5
  • That code isnt updating or doing anything with a DataGridView. Those DB provider objects are very powerful such that when used to their potential rather than code to UPDATEs or DELETEs one by one, they will do it all, and most changes are immediately seen in a DGV. There are massive numbers of posts here on how to do so (as well as MS Docs, of course). – Ňɏssa Pøngjǣrdenlarp Dec 26 '20 at 19:54
  • Please share your datagrid binding codes to be more clarified, By binding codes I mean the codes that you are retrieving the data and loading into datagrid. – Amir Dec 26 '20 at 19:59
  • so, you are saying the code only updates the datagridview? – Souz4x Dec 26 '20 at 21:59
  • i don´t know what is datagrid binding codes, could you explain a little more specific, as i said im very new to c# – Souz4x Dec 26 '20 at 22:00
  • Code appears to update record in Access database but does not refresh the DGV. Does this answer your question? [How can I refresh c# dataGridView after update ?](https://stackoverflow.com/questions/7008361/how-can-i-refresh-c-sharp-datagridview-after-update) – June7 Dec 27 '20 at 08:50

0 Answers0