using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter roll to search");
int roll = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter Name to search");
string n = Console.ReadLine();
Console.WriteLine(n);
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\db1.mdb");
int i = db1.search(roll,n,con);
//Console.WriteLine("search
successful........");
//con.Open();
// OleDbCommand cmd = new OleDbCommand("select *
from student ", con);
// OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(cmd);
// DataSet ds = new DataSet();
// myDataAdapter.Fill(ds,"student");
// foreach (DataRow dr in
ds.Tables["student"].Rows)
// {
//for (int j = 0 ; j <2 ; j++)
// {
// Console.WriteLine(dr[j].ToString());
// }
// Console.ReadLine();
//Class1.DELETE_(con);
//Update.UPDATE_(con);
//con.Open();
// OleDbCommand nonqueryCommand =
con.CreateCommand();
// Console.WriteLine("Enter roll to DELETE
corresponding student information::");
// int roll = Int32.Parse(Console.ReadLine());
// nonqueryCommand.CommandText = "DELETE FROM
student WHERE " + "roll=" + roll + "";
//Console.WriteLine("Executing {0}",
nonqueryCommand.CommandText);
//Console.WriteLine("Number of rows affected :
{0}", nonqueryCommand.ExecuteNonQuery());
//Console.Read();
//con.Close();
//}
}
}
}
Using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
namespace ConsoleApplication1
{
class db1
{
public static int search(int roll,string
prasad,OleDbConnection con)
{
con.Open();
OleDbCommand cmd;
cmd = new OleDbCommand("select * from student
where roll= " + roll + "and name='" + prasad + "'", con);
OleDbDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
int i = dr.GetInt32(0);
string s = dr.GetString(1);
System.Console.WriteLine(i);
System.Console.WriteLine(s);
}
Console.ReadLine();
con.Close();
return 1;
}
}
}
namespace ConsoleApplication1
{
class Class1
{
public static void DELETE_(OleDbConnection con)
{
try
{
con.Open();
Console.WriteLine("Enter the role number of
the student whose details be deleted::");
int role = Int32.Parse(Console.ReadLine());
OleDbCommand cmd = new OleDbCommand("delete
from student where roll=" + role + "", con);
int i = cmd.ExecuteNonQuery();
Console.WriteLine("Number of rows affected:"
+ i);
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
finally
{
con.Close();
Console.Read();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
namespace ConsoleApplication1
{
class Update
{
public static void UPDATE_(OleDbConnection con)
{
con.Open();
Console.WriteLine("Enter the Roll no. of the
student whose details will be updated::");
int r = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the new ROLL ::");
int nr = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the new NAME::");
string s = Console.ReadLine();
OleDbCommand com = new OleDbCommand("update
student set roll=" + nr + " and name=' " + s + " ' where
roll=" + r + "",con);
int i=com.ExecuteNonQuery();
Console.WriteLine(+ i + "number of rows
updated........");
con.Close();
Console.ReadLine();
}
}
}