dria o
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
namespace detabes
{
class Student
{
OleDbConnection cn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Students Account\Desktop\sean\detabes.mdb");
private int _id;
/// <summary>
/// primary key
/// </summary>
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _lastName;
/// <summary>
/// lastname lang ni
/// </summary>
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}
private string _firstName;
/// <summary>
/// firstname lang ni
/// </summary>
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
private string _middleName;
/// <summary>
/// middlename lang ni
/// </summary>
public string MiddleName
{
get { return _middleName; }
set { _middleName = value; }
}
public bool add()
{
try
{
this._firstName = string.Empty;
this._middleName = string.Empty;
this._lastName = string.Empty;
return true;
}
catch (Exception ex)
{
return false;
}
}
public void Connect()
{
try
{
if (cn.State == ConnectionState.Open)
cn.Close();
cn.Open();
/*MessageBox.Show("Connection Success");
OleDbCommand cmd = new OleDbCommand("Select * from Student", cn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
grdData.DataSource = dt;*/
}
catch (Exception ex)
{
throw new Exception("Unable to connect to the database. \n" + ex.Message);
//MessageBox.Show("Connection Failed." + ex.Message);
}
}
public DataTable GetStudentData()
{
OleDbCommand cmd =
new OleDbCommand("select * from Student", cn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
- All about me | Time: 2:08 pm (UTC+8) Comments (2)

