namespace OEFEN
{
public partial class Form1 : Form
{
public string DBFile;
public OleDbConnection myDB;
public string conn = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=";
public string searchString;
public Form1()
{
InitializeComponent();
}
private void openDBToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
DBFile = openFileDialog1.FileName;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void listToolStripMenuItem_Click(object sender, EventArgs e)
{
myDB = new OleDbConnection(conn+DBFile);
myDB.Open();
OleDbDataAdapter myDB_Adapter = new OleDbDataAdapter(@"SELECT * FROM Students ", myDB);
DataSet ds = new DataSet();
myDB_Adapter.Fill(ds, "Students");
dataGridView1.DataSource = ds;
dataGridView1.DataMember="Students";
myDB.Close();
}
private void searchToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 iets = new Form3();
iets.StartPosition = FormStartPosition.CenterScreen;
iets.Show();
}
public void Search()
{
myDB = new OleDbConnection(conn+DBFile);
myDB.Open();
OleDbDataAdapter anderAdapter = new OleDbDataAdapter(@"SELECT * FROM Students WHERE st_Surname=" + searchString, myDB);
DataSet kk = new DataSet();
anderAdapter.Fill(kk, "List");
dataGridView1.DataSource = kk;
dataGridView1.DataMember = "List";
myDB.Close();
}
}
}