|
Introduction
Usage Guide
Sample code
Class Reference
Feedback
Project Homepage
|
Stitch.Database Sample Code
Sample select statement
The example below shows a SELECT based statement being dynamically created for SQL Server.
DBConnection dbConnection = new DBConnection(DatabaseType.MSSQL,
"localhost",
"username",
"password",
"Northwind");
DBResult dbResult = dbConnection.SelectQuery("SELECT * FROM
tblBooks WHERE 1");
DBRow dbRow = dbResult.FetchArray();
while (dbRow != null)
{
Console.WriteLine("Book: " + dbRow["BookName"]);
Console.WriteLine("Author: " + dbRow["AuthorName"]);
dbRow = dbResult.FetchArray();
}
Sample Insert statement
The example below shows an INSERT based statement being dynamically created for Microsoft Access.
DBConnection dbConnection = new DBConnection(DatabaseType.Access,
"AuthorData.mdb");
int LinesAffected = dbConnection.NonSelectQuery("INSERT INTO tblBooks
(Author, Title)
VALUES
('Paul Stovell',
'The Big Book of Everything')");
Stored Procedures
As of Stitch.Database 1.1.0.0, Stored Procedures are supported for both Access and SQL Server.
Parameters to procedures are passed using the DBParameter class.
DBConnection dbConnection = new DBConnection(DatabaseType.MSSQL,
"localhost",
"username",
"password",
"Northwind");
string BookName = "The Big Book of Everything";
DBResult dbResult = dbConnection.StoredProcedure("spGetBooks",
new DBParameter("@BookName",
SqlDbType.Char,
BookName.Length,
BookName));
DBRow dbRow = dbResult.FetchArray();
while (dbRow != null)
{
Console.WriteLine("Book: " + dbRow["BookName"]);
Console.WriteLine("Author: " + dbRow["AuthorName"]);
dbRow = dbResult.FetchArray();
}
Copyright (C) Paul Stovell, 2004. All rights reserved.
This product is subject to the terms and conditions detailed in the
licence agreement.
|