TAILIEUCHUNG - 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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.