Update all records of the gridview at one time in ASP. net2.0
Source: Internet
Author: User
In Asp.net 2.0, the gridview control is a very good control. In some cases
All rows are text boxes. How do I update all modified records at a time? There are two methods, one is to use sqldatasource to update
All records, but this method is slow, because every time you update a record, you must establish a data connection and execute updatecommand, which will affect the performance,
But let's first look at the implementation method:
Sqlconnection con = new sqlconnection (configurationsettings. connectionstrings ["appconnectionstring1"]. connectionstring );
Sqlcommand command = new sqlcommand (query. tostring (), con );
Con. open ();
Command. executenonquery ();
Con. Close ();
}
Void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Sqlconnection con = new sqlconnection (configurationsettings. connectionstrings ["appconnectionstring1"]. connectionstring );
Sqlcommand command = new sqlcommand ("select [customerid], [companyName], [contactname], [contacttitle] from [Customers]", con );
Con. open ();
Gridview1.datasource = command. executereader ();
Gridview1.databind ();
Con. Close ();
}
}
</SCRIPT>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.