Đang chuẩn bị liên kết để tải về tài liệu:
Modifying Rows in a DataTable phần 2

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

// step 3: use the Add() method through the Rows property // to add the new DataRow to the DataTable Console.WriteLine("Calling myDataTable.Rows.Add()") | step 3 use the Add method through the Rows property to add the new DataRow to the DataTable Console.WriteLine Calling myDataTable.Rows.Add myDataTable.Rows.Add myNewDataRow Console.WriteLine myNewDataRow.RowState myNewDataRow.RowState step 4 use the Update method to push the new row to the database Console.WriteLine Calling mySqlDataAdapter.Update mySqlConnection.Open int numOfRows mySqlDataAdapter.Update myDataTable mySqlConnection.Close Console.WriteLine numOfRows numOfRows Console.WriteLine myNewDataRow.RowState myNewDataRow.RowState 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 ADO.NET 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 .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.