Stitch.Database Sample Code
Sample select statement // Create connection to SQL Server // Server name: Localhost // Database name: Northwind DBConnection dbConnection = new DBConnection(DatabaseType.MSSQL, "localhost", "username", "password", "Northwind"); // Query the database DBResult dbResult = dbConnection.SelectQuery("SELECT * FROM tblBooks WHERE 1"); DBRow dbRow = dbResult.FetchArray(); // Display the results while (dbRow != null) { Console.WriteLine("Book: " + dbRow["BookName"]); Console.WriteLine("Author: " + dbRow["AuthorName"]); dbRow = dbResult.FetchArray(); }
Sample Insert statement // Create connection to Access file AuthorData.mdb DBConnection dbConnection = new DBConnection(DatabaseType.Access, "AuthorData.mdb"); // Query the database int LinesAffected = dbConnection.NonSelectQuery("INSERT INTO tblBooks (Author, Title) VALUES ('Paul Stovell', 'The Big Book of Everything')");
Stored Procedures // Create connection to SQL Server // Server name: Localhost // Database name: Northwind DBConnection dbConnection = new DBConnection(DatabaseType.MSSQL, "localhost", "username", "password", "Northwind"); // Call stored procedure "spGetBooks" string BookName = "The Big Book of Everything"; DBResult dbResult = dbConnection.StoredProcedure("spGetBooks", new DBParameter("@BookName", // Parameter name SqlDbType.Char, // Type BookName.Length, // Size BookName)); // Value DBRow dbRow = dbResult.FetchArray(); // Display the results while (dbRow != null) { Console.WriteLine("Book: " + dbRow["BookName"]); Console.WriteLine("Author: " + dbRow["AuthorName"]); dbRow = dbResult.FetchArray(); }
Copyright (C) Paul Stovell, 2004. All rights reserved. |