About server-side data access (2) Two ways access to SQL-based data:

zhaozj2021-02-16  110

Two ways access SQL-based data:

1) Use SqlDataAdapter

SqlConnection myConnection = new SqlConnection ( "server = (local) // NetSDK; database = pubs; Trusted_Connection = yes"); SqlDataAdapter myCommand = new SqlDataAdapter ( "select * from Authors", myConnection); DataSet ds = new DataSet (); MyCommand.Fill (DS, "author"); mydatagrid.datasource = ds.tables ["author"] .defaultView; mydatagrid.databind ();

2) Use SqlDataReader

SqlConnection myConnection = new SqlConnection ( "server = (local) // NetSDK; database = pubs; Trusted_Connection = yes"); SqlCommand myCommand = new SqlCommand ( "select * from Authors", myConnection);

MyConnection.open ();

SqlDataReader Dr = mycommand.executeReader ();

MyDataGrid.datasource = DR; mydatagrid.databind ();

MyConnection.Close ();

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

New Post(0)