tailieunhanh - Creating a Table in the Database from a DataTable Schema

[ Team LiB ] Recipe Creating a Table in the Database from a DataTable Schema Problem You need to create a table in a database from an existing DataTable schema. Solution Use the CreateTableFromSchema( ) method shown in this solution. | Team LiB Recipe Creating a Table in the Database from a DataTable Schema Problem You need to create a table in a database from an existing DataTable schema. Solution Use the CreateTableFromSchema method shown in this solution. The sample code contains one event handler and two methods Creates a DataTable containing the schema from the Orders table in the Northwind sample database. The method CreateTableFromSchema in the sample code is called to create a table in the database from this schema. CreateTableFromSchema This method creates a schema in the database for the schema of the DataTable argument. The method builds a DDL statement from the schema information and executes it against the data source specified by the connection string argument to create the table. NetType2SqlType This method is called by the CreateTableFromSchemaMethod to map .NET data types to SQL Server types when building the DDL statement. The C code is shown in Example 10-15. Example 10-15. File Namespaces variables and constants using System using using using using using . . . private void goButton_Click object sender e Fill a table with the Orders table schema. String sqlText SELECT FROM Orders SqlDataAdapter da new SqlDataAdapter sqlText S ql_ConnectString DataTable dt new DataTable Orders dt CreateTableFromSchema dt S ql_ConnectString Table TABLENAME created. Create DataTable from schema. private void CreateTableFromSchema DataTable dt String connectionString Drop the new table if it is already there. StringBuilder sqlCmd new StringBuilder if exists SELECT FROM WHERE id object_id TABLENAME AND OBJECTPROPERTY id IsUserTable 1 .

crossorigin="anonymous">
Đã 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.