Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SqlCommand cmd = new SqlCommand("exec insertDepartement @DepartmentName", con);
cmd.Parameters.AddWithValue("@DepartmentName", TextBox1.Text);
con.Close();
con.Open();
cmd.ExecuteNonQuery();

Page_Load(sender, e);
Posted
Comments
manognya kota 5-Nov-12 7:50am    
How are you loading your grid.Can you post that code?
Gilbertinino 5-Nov-12 7:54am    
i dont know the code of how to reload the gridview. And it is what am looking for.
dimpledevani 5-Nov-12 7:50am    
Please explain your query in detail and what is the above code for??
Gilbertinino 5-Nov-12 7:52am    
the code is about inserting a record but i don't know how after inserting to reload the page and see what am coming to insert.
dimpledevani 5-Nov-12 7:55am    
The code which you have posted in that only in the pageload function write call a proc to retriev the details (select cmd) and show it in a control like gridview

hi,

After you execute the insert statement.Call the function to get the dataset and bind it to the gridview.

Hope this helps.
 
Share this answer
 
Hi..No need to refresh the whole page to display last inserted record...?Follow these steps :

First use the ajax update panel for gridview

Next,call the grid binded method after the cmd.executenonquery()..see the example below

C#
SqlCommand cmd = new SqlCommand("exec insertDepartement @DepartmentName", con);
            cmd.Parameters.AddWithValue("@DepartmentName", TextBox1.Text);            
            con.Close();
            con.Open();
            cmd.ExecuteNonQuery();
            bindgrid();


create a method called bindgrid()

C#
public void bindgrid()
{
  sqlcommand com=new sqlcommand("select * from table");
sqladapter da=new sqladapter(com,con);
da.Fill(ds)
    gridview1.datasource=ds;
    gridview1.databind();
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900