/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SampleApp.Odbc/VB/source.vb
52 строки
2 KB
Genevieve Warren
SFI - ROPC work - VB snippets part 1 (#42691)
24 сен 2024, 21:39
Не верифицирован
24 сен 2024, 21:39
7f6485e
Код
Авторство
О чём код?
' <Snippet1> Option Explicit On Option Strict On Imports System.Data.Odbc Public Class Program Public Shared Sub Main() ' The connection string assumes that the Access ' Northwind.mdb is located in the c:\Data folder. Dim connectionString As String = "..." ' Provide the query string with a parameter placeholder. Dim queryString As String = "SELECT ProductID, UnitPrice, ProductName from Products " _ & "WHERE UnitPrice > ? " _ & "ORDER BY UnitPrice DESC;" ' Specify the parameter value. Dim paramValue As Integer = 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 connection As New OdbcConnection(connectionString) ' Create the Command and Parameter objects. Dim command As New OdbcCommand(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() Dim dataReader As OdbcDataReader = command.ExecuteReader() Do While dataReader.Read() Console.WriteLine( vbTab & "{0}" & vbTab & "{1}" & vbTab & "{2}", dataReader(0), dataReader(1), dataReader(2)) Loop dataReader.Close() Catch ex As Exception Console.WriteLine(ex.Message) End Try Console.ReadLine() End Using End Sub End Class ' </Snippet1>