Chapter 22 Quick Reference


Do this

Use ADO.NET classes.

If you are using Visual Studio .NET, you will need to add only a using directive for the appropriate data provider. For example:

using namespace System::Data::SqlClient;

Connect to a database.

Create a SqlConnection or OleDbConnection object, and configure its ConnectionString property.

Create a command object.

Create a SqlCommand or OleDbCommand object, and configure its CommandText, CommandType, and Connection properties.

Execute a command.

If the command returns a scalar value, call ExecuteScalar. If the command modifies the database, call ExecuteNonQuery. If the command performs a query, call ExecuteReader. Assign the result to a SqlDataReader or OleDbReader object, and use this reader to loop through the result set. For example:

OleDbDataReader * reader = cmProducts->ExecuteReader(); while (reader->Read()) { Console::Write(reader->GetString(0)); }

Use data in a disconnected application.

Create a SqlDataAdapter (or OleDbAdapter), and specify commands to access the database. Create a DataSet, and fill the DataSet by using the data adapter. For example:

daTitles = new OleDbDataAdapter( S"SELECT * FROM Titles", cnNwind); dsTitles = new DataSet("Titles"); daTitles->Fill(dsTitles);

Display a DataSet in a

Use the DataSource property of DataGrid. For example:

dgTitles->DataSource = dsTitles->Tables->Item[0]->DefaultView; 

Microsoft Visual C++  .NET(c) Step by Step
Microsoft Visual C++ .NET(c) Step by Step
ISBN: 735615675
Year: 2003
Pages: 208 © 2008-2017.
If you may any questions please contact us: