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);
}
}
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE