/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SampleApp.OleDb/CS/source.cs
57 строк
2 KB
Genevieve Warren
ropc fixes for ado.net (#42498)
07 сен 2024, 02:05
Не верифицирован
07 сен 2024, 02:05
cdcd7c4
Код
Авторство
О чём код?
// <Snippet1> using System; using System.Data.OleDb; using System.Runtime.Versioning; // API is only supported on Windows [SupportedOSPlatform("windows")] static class Program { static void Main() { const string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "c:\\Data\\Northwind.mdb;..."; // Provide the query string with a parameter placeholder. const string queryString = "SELECT ProductID, UnitPrice, ProductName from products " + "WHERE UnitPrice > ? " + "ORDER BY UnitPrice DESC;"; // Specify the parameter value. const int paramValue = 5; // Create and open the connection in a using block. This // ensures that all resources will be closed and disposed // when the code exits. using (OleDbConnection connection = new(connectionString)) { // Create the Command and Parameter objects. OleDbCommand command = new(queryString, connection); command.Parameters.AddWithValue("@pricePoint", paramValue); // Open the connection in a try/catch block. // Create and execute the DataReader, writing the result // set to the console window. try { connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine("\t{0}\t{1}\t{2}", reader[0], reader[1], reader[2]); } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); } } // </Snippet1> }