Custom DataSet

xiaoxiao2021-03-06  39

private System.Data.SqlClient.SqlConnection myConnection; private System.Data.SqlClient.SqlCommand myCommand; private System.Data.DataSet myDataSet; private System.Data.SqlClient.SqlDataAdapter myDataAdapter; // create a connection object and open its string connectionString = " Server = .; uid = sa; pwd =; database = northwind "; myconnection = new system.data.sqlclient.sqlConnection (connectionstring); myconnection.open ();

// Create a DataSet and set its nature myDataSet = new system.data.dataset (); myDataSet.casensITIVE = true; // Create a sqlcommand object and assign a value to it to connect objects and SELECT statement myCommand = new system.data.sqlclient.sqlcommand (); Mycommand.connection = myconnection; mycommand.commandtext = "Select * from customers";

// Create a DataAdapter object and pass SqlCommand object, and create a table insinuate myDataAdapter = new System.Data.SqlClient.SqlDataAdapter (); myDataAdapter.SelectCommand = myCommand; myDataAdapter.TableMappings.Add ( "Table", "Customers");

MyDataAdapter.fill (MyDataSet); CustomersDataGrid.dataSource = mydataset.tables ["Customers"]. defaultView;

转载请注明原文地址:https://www.9cbs.com/read-77537.html

New Post(0)