Namespace - LJCDataAccess
Syntax
C# |
public class DataAccess
|
Implements an ADO.NET SQL data access control layer
(DE).
Remarks
The Data Access class encapsulates the repetitive code required to
perform common database functions using ADO.Net. This reduces the amount
of application code required to access this functionality and provides a
standard location for implementing common best practices.
This class is capable of connecting using the SQL Server data provider,
OLEDB driver, ODBC driver or MySQL data provider.
The most commonly used methods are
GetDataTable(),
ExecuteNonQuery() and
GetSchemaOnly().
Constructor
#ctor
|
Initializes an object instance with the provided values. |
Insert Update and Delete
Select Methods
FillDataTable
|
Executes a Select statement and fills the specified
DataTable.
(E) |
GetDataReader
|
Executes a Select statement and retrieves the
DbDataReader
object.
(E) |
GetDataSet
|
Executes a Select statement and retrieves the
DataSet
object.
(E) |
GetDataTable
|
Executes a Select statement and retrieves the
DataTable
object.
(E) |
GetSchemaOnly
|
Retrieves the
DataTable
object with schema only.
(E) |
Script Methods
Stored Procedure
Other Public Methods
13 Methods
Other Private Methods
3 Methods
Properties
Example
This is main function sample code for testing. The code for the additional
test functions is listed under the methods with the same names.
C# |
using System;
using System.Data;
using System.Data.Common;
using System.IO;
using LJCDataAccess;
using LJCDataAccessConfig;
private static void TestDataAccess()
{
DataAccess dataAccess;
string connectionString;
string providerName;
bool useInternal = false;
if (useInternal)
{
var connectionBuilder = new DbConnectionStringBuilder()
{
{ "Data Source", "DataServiceName" },
{ "Initial Catalog", "DatabaseName" },
{ "Integrated Security", "True" }
};
connectionString = connectionBuilder.ConnectionString;
providerName = "System.Data.SqlClient";
}
else
{
DataConfigs dataConfigs = new DataConfigs();
dataConfigs.LJCLoadData();
dataConfig = dataConfigs.LJCGetByName("ConfigName");
connectionString = dataConfig.GetConnectionString();
providerName = dataConfig.GetProviderName();
}
dataAccess = new DataAccess(connectionString, providerName);
GetDataReader(dataAccess);
GetDataTable(dataAccess);
GetDataSet(dataAccess);
GetProcedureDataTable(dataAccess);
FillDataTable(dataAccess);
GetSchemaOnly(dataAccess);
ExecuteNonQuery(dataAccess);
ExecuteScript(dataAccess);
ExecuteScriptText(dataAccess);
}
IF NOT EXISTS(SELECT* FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = N'PersonTest')
BEGIN
CREATE TABLE[dbo].[PersonTest]
(
[Id][int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar] (60) NULL,
[PrincipleFlag] [bit] NOT NULL,
CONSTRAINT[PK_PersonTest]
PRIMARY KEY CLUSTERED(
[Id] ASC),
)
END
GO
|
Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.