hello guys how can i update datagridview to display the newly added data to the database

here is my sample code for adding data to the database

MySqlCommand cmdAdd = new MySqlCommand("INSERT INTO tblelemdetails (STUD_ID,LNAME,FMNAME,AGE,ADDRESS,BDAY,BPLACE,RELIGION,CITIZEN,CITY,LSCHOOL,LSCHOOLADD,SCHOOLYEAR,GENDER,LEVEL) VALUES('" + Ids.ToString() + "','" + txtLName.Text + "','" + fnamer + "','" + txtAge.Text + "','" + txtHAddress.Text + "','" + bdayer + "','" + txtPOBirth.Text + "','" + txtReligion.Text + "','" + txtCitizen.Text + "','" + txtCity.Text + "','" + txtLSchool.Text + "','" + txtLSchoolAdd.Text + "','" + txtSY.Text + "','" + cmbGender.Text + "','" + cmbYrLvl.Text + "')", db_con.DbConn);
                cmdAdd.Transaction = mytrans;
                cmdAdd.ExecuteNonQuery();
                cmdAdd.Dispose();
                mytrans.Commit();
                MessageBox.Show("Data Has Been Succesfully Added","Important Note",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                Clear();
                db_con.DbConn.Close();

pls need some help and thanks

You will either need to re-select the data from the database OR put the inserted rows into a class or other container (like a GridViewRow) that is the same shape as your GridView and add it to the GridView.

is it posible to repopulate the datagridview?

yes just do datagridview1.clear() then do what you did to populate it the first time round. i think that works . . .

i applied repopulate the datagridview but it doesn't work.

Does this mean you tried the .Clear() method of the data grid view and following that used the populated the grid view the same way you had in the originally ?

yup, i already used that kind of approach but it does not update the datagridview?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.