Home > DeveloperSection > Forums > How to refresh gridview after every insert command automatically?
Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    August-28-2014 1:34 AM

 C#
Ratings:


 1 Reply(s)
 816  View(s)
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.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 2:21 AM

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)

        {

        }

    }


Don't want to miss updates? Please click the below button!

Follow MindStick