tailieunhanh - Modifying Rows in a DataTable phần 2

// step 3: use the Add() method through the Rows property // to add the new DataRow to the DataTable ("Calling ()") | step 3 use the Add method through the Rows property to add the new DataRow to the DataTable Calling myNewDataRow step 4 use the Update method to push the new row to the database Calling int numOfRows myDataTable numOfRows numOfRows DisplayDataRow myNewDataRow myDataTable You ll notice I call the Open and Close methods of mySqlConnection around the call to the Update method. You don t have to do this because the Update method-like the Fill method-will automatically open and then close mySqlConnection if it is currently closed. It is good programming practice however to explicitly include the Open and Close calls so that you can see exactly what is going on. Note In the disconnected model of data access you should typically keep the connection to the database open for as short a period as possible. Of course if you re making a lot of calls to the Update or the Fill method over a short time you could keep the connection open and then close it when you re finished. That way your code will have better performance. You might need to experiment with your own programs to find the right balance. The Update method is overloaded as follows int Update DataRow myDataRows int Update DataSet myDataSet int Update DataTable myDataTable int Update DataRow myDataRows DataTableMapping myDataTableMapping int Update DataSet myDataSet string dataTableName where dataTableName is a string containing the name of the DataTable to update. The int returned by the Update method is the number of rows successfully updated in the database. Going back to the previous AddDataRow method you ll also notice the inclusion of Console .WriteLine calls that display the RowState property of .

TÀI LIỆU LIÊN QUAN
10    158    1
6    184    1
7    162    1
5    157    1
6    160    1
6    152    1
6    150    1
6    206    1
7    154    1
5    121    1