ODBC driver companion for CommonNetFuncs.Sql.Common
$ dotnet add package CommonNetFuncs.Sql.OdbcThis project contains helper methods for executing SQL queries and commands against an ODBC database.
Helper methods for executing SQL queries and commands directly against an ODBC database.
Executes a SELECT query asynchronously and returns the results as a DataTable.
string sql = "SELECT * FROM TestTable";
using DataTable queryResultsTable = await DirectQuery.GetDataTable(sql, connectionString); // queryResultsTable will contain the results of the query
Executes a SELECT query synchronously and returns the results as a DataTable.
string sql = "SELECT * FROM TestTable";
using DataTable queryResultsTable = DirectQuery.GetDataTable(sql, connectionString); // queryResultsTable will contain the results of the query
Executes an UPDATE, INSERT, or DELETE query asynchronously and returns an UpdateResult containing the number of affected rows and a boolean indicating success.
string sql = "UPDATE TestTable SET Name = 'Updated' WHERE Name LIKE 'Test%'";
UpdateResult updateResult = await DirectQuery.RunUpdateQuery(sql, connectionString); // { RecordsChanged = 1, Success = true }
Executes an UPDATE, INSERT, or DELETE query synchronously and returns an UpdateResult containing the number of affected rows and a boolean indicating success.
string sql = "UPDATE TestTable SET Name = 'Updated' WHERE Name LIKE 'Test%'";
UpdateResult updateResult = DirectQuery.RunUpdateQuerySynchronous(sql, connectionString); // { RecordsChanged = 1, Success = true }
Gets a data from a query synchronously and returns an IEnumerable of the query result type.
string sql = "SELECT * FROM TestTable";
IEnumerable<TestEntity> queryResults = DirectQuery.GetDataStreamSynchronous(sql, connectionString); // queryResults will contain the results of the query as TestEntity objects
Gets a data from a query asynchronously and returns an IAsyncEnumerable of the query result type.
List<TestModel> results = new();
string sql = "SELECT * FROM TestTable";
await foreach (TestModel item in DirectQuery.GetDataStreamAsync<TestModel>(sql, connectionString))
{
results.Add(item); // Results will contain all items returned by the query
}
Gets a data from a query asynchronously and returns an IEnumerable of the query result type.
string sql = "SELECT * FROM TestTable";
IEnumerable<TestEntity> queryResults = await DirectQuery.GetDataDirectAsync(sql, connectionString); // queryResults will contain the results of the query as TestEntity objects
Install via NuGet:
dotnet add package CommonNetFuncs.Sql.Odbc
This project is licensed under the MIT License - see the LICENSE file for details.