TAILIEUCHUNG - ASP.NET 4 Unleased - p 93

Building Data Access Components with void Page_Load() { // Create connection string connectionString = [“Movies”].ConnectionString; SqlConnection con = new SqlConnection(connectionString); // Create Select command dad = new SqlDataAdapter(“SELECT Id,Title,Director FROM Movies”, con); // Create Update, Insert, and Delete commands with SqlCommandBuilder SqlCommandBuilder builder = new SqlCommandBuilder(dad); // Add data to DataTable dtblMovies = new DataTable(); (dtblMovies); // Bind data to Repeater = dtblMovies; (); } protected void lnkUpdate_Click(object sender, EventArgs e) { // Update DataTable with changes for (int i=0; i . | 894 CHAPTER 19 Building Data Access Components with void Page_Load Create connection string connectionstring Movies .ConnectionString SqlConnection con new SqlConnection connectionString Create Select command dad new SqlDataAdapter SELECT Id Title Director FROM Movies con Create Update Insert and Delete commands with SqlCommandBuilder SqlCommandBuilder builder new SqlCommandBuilder dad Add data to DataTable dtblMovies new DataTable dtblMovies Bind data to Repeater dtblMovies protected void lnkUpdate_Click object sender EventArgs e Update DataTable with changes for int i 0 i i Repeateritem item i TextBox txtTitle TextBox txtTitle TextBox txtDirector TextBox txtDirector if i Title i Title if i Director i Director Set batch size to maximum size 0 Perform update int numUpdated dtblMovies Updated 0 rows numUpdated script html xmlns http 1999 xhtml head id Head1 runat server From the Library of Wow eBook Disconnected Data Access 895 title Show DataAdapter Update title head body form id form1 runat server div asp Repeater id rptMovies EnableViewState false Runat server HeaderTemplate table tr th Title th th Director th tr HeaderTemplate ItemTemplate tr td asp TextBox id txtTitle Text Eval Title Runat server td td asp TextBox id txtDirector Text Eval Director Runat server td tr ItemTemplate FooterTemplate table FooterTemplate asp Repeater br asp LinkButton id lnkUpdate Text Update Movies Runat server OnClick lnkUpdate_Click br br 19 From the Library of Wow eBook 896 CHAPTER 19 Building Data Access Components with asp Label id lblResults EnableViewState false Runat server div form body html The .