HOW TO REFRESH GRIDVIEW AFTER EVERY INSERT COMMAND AUTOMATICALLY?

Pravesh Singh

Total Post:101

Points:709
Posted by  Pravesh Singh
C#
 1156  View(s)
Ratings:
Rate this:

I am inserting data to database when i click submit button data inserted into Database but no changes get reflected in GridView without refreshing the page.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: How to refresh gridview after every insert command automatically?

    Hi Pravesh, 


    public void GetData()       

        {

            try

            {

                SqlConnection connection = new SqlConnection();

                connection.ConnectionString = ConfigurationManager.ConnectionStrings["mysql"].ConnectionString;

                String sql = "Your Query";

                DataSet ds = new DataSet();

                SqlDataAdapter da = new SqlDataAdapter(sql, connection);

                da.Fill(ds);

                DataTable dt = new DataTable();

                dt = ds.Tables[0];

                GridView1.DataSource = dt;

            }

            catch (SqlException ex)

            {

            }

            catch (Exception e)

            {

            }

        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!