using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace bankAccount
{
class Program
{
static void Main(string[] args)
{
DataBaseDemo1();
}
static void DataBaseDemo1()
{
try
{
//Query user
Console.WriteLine("Enter Bank account Number ");
double a = Convert.ToDouble(Console.ReadLine());
//Check database for matching records
string sConnection;
sConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Dayspace\bank.mdb";
OleDbConnection dbConn;
dbConn = new OleDbConnection(sConnection);
dbConn.Open();
string sql;
sql = "SELECT LastName, FirstName, CurrentBalance FROM bankAccountTable WHERE AccountNumber = " + Convert.ToString(a);
OleDbCommand dbCmd = new OleDbCommand();
dbCmd.CommandText = sql; // set command SQL string
dbCmd.Connection = dbConn; // dbConn is connection object
OleDbDataReader dbReader;
dbReader = dbCmd.ExecuteReader();
if (dbReader.Read())
{
Console.WriteLine("First Name: " + dbReader["FirstName"] + "\t Last Name: " + dbReader["LastName"] + "\t Balance: " + dbReader["CurrentBalance"]);
}
else
{
Console.WriteLine("No matching record");
}
dbReader.Close(); // Close the Reader object
dbConn.Close(); // Close the Connection object
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
|