KEMBAR78
Answers | PDF | Data Management | Programming Paradigms
0% found this document useful (0 votes)
2 views8 pages

Answers

Uploaded by

andarykareem63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Answers

Uploaded by

andarykareem63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

public partial class Form1 : Form

public Form1()

InitializeComponent();

OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" +

"Data Source=C:\\Users\\karou\\Documents\\Sections.accdb");

private object sqlQueryString;

private void LoginBtn_Click(object sender, EventArgs e)

if (cn.State == ConnectionState.Closed)

cn.Open();

OleDbCommand cmd = new OleDbCommand("SELECT COUNT(*) FROM users where


userID = ? and password = ?", cn);

//DataTable dt = new DataTable();

//OleDbDataAdapter adp = new OleDbDataAdapter(cmd);

//adp.Fill(dt);

cmd.Parameters.AddWithValue("?", userTxt.Text);

cmd.Parameters.AddWithValue("?", passwordTxt.Text);

int count = (int)cmd.ExecuteScalar();

if (count == 1)

MessageBox.Show("Welcome");

}
else

MessageBox.Show("Error");

private void loadSections(string sqlQueryString)

if (cn.State == ConnectionState.Closed)

cn.Open();

try

// ERROR ON THE DEPARTMENT ID RELATION BETWEEN TABLES;

OleDbCommand cmd1 = new OleDbCommand("SELECT sectionID,


sectionName,departmentID, sectionLanguage, Branch, startingYear FROM sections", cn);

DataTable dt = new DataTable();

OleDbDataAdapter adp = new OleDbDataAdapter(cmd1);

adp.Fill(dt);

sectionDvg.DataSource = dt;

sectionDvg.Columns["sectionID"].Visible = false;

catch (Exception ex)

MessageBox.Show(ex.Message);

cn.Close();
}

private void tabPage2_Click(object sender, EventArgs e)

private void Form1_Load(object sender, EventArgs e)

cn.Open();

loadSections("");

OleDbCommand cmd2 = new OleDbCommand("SELECT departmentName,departmentID


FROM departments", cn);

DataTable dt2 = new DataTable();

OleDbDataAdapter adp1 = new OleDbDataAdapter(cmd2);

adp1.Fill(dt2);

comboDep.DataSource = dt2;

comboDep.DisplayMember = "departmentName";

comboDep.ValueMember = "departmentID";

comboDep.SelectedIndex = 0;

OleDbCommand cmd3 = new OleDbCommand("SELECT departmentName,departmentID


FROM departments", cn);

DataTable dt3 = new DataTable();

OleDbDataAdapter adp2 = new OleDbDataAdapter(cmd3);


adp2.Fill(dt3);

comboSearchType.DataSource = dt3;

comboSearchType.DisplayMember = "departmentName";

comboSearchType.ValueMember = "departmentID";

comboSearchType.SelectedIndex = 0;

/*OleDbCommand cmd4 = new OleDbCommand("SELECT sectionID,


sectionName,departmentID, sectionLanguage, Branch, startingYear FROM sections", cn);

DataTable dt4 = new DataTable();

OleDbDataAdapter adp4 = new OleDbDataAdapter(cmd4);

adp4.Fill(dt4);

comboSearchType.DataSource = dt3;

comboSearchType.DisplayMember = "departmentName";

comboSearchType.ValueMember = "departmentID";

comboSearchType.SelectedIndex = 0;

*/

cn.Close();

int i = 0;

private void InsertBtn_Click(object sender, EventArgs e)

cn.Open();

OleDbCommand cmd4 = new OleDbCommand("INSERT INTO sections


(sectionName,departmentID, sectionLanguage,Branch, startingYear)" +
" VALUES (?,?,?,?,?)", cn);

cmd4.Parameters.AddWithValue("?", titleTxt.Text);

cmd4.Parameters.AddWithValue("?", comboDep.Text);

cmd4.Parameters.AddWithValue("?", languageTxt.Text);

if (i == 1)

cmd4.Parameters.AddWithValue("?", "Saida");

else

cmd4.Parameters.AddWithValue("?", "Abey");

cmd4.Parameters.AddWithValue("?", startingYearTxt.Text);

cmd4.ExecuteNonQuery();

MessageBox.Show("Data Added");

cn.Close();

private void languageTxt_TextChanged(object sender, EventArgs e)

}
private void SaidaRdb_CheckedChanged(object sender, EventArgs e)

i = 1;

private void AbeyRdb_CheckedChanged(object sender, EventArgs e)

private void deleteBtn_Click(object sender, EventArgs e)

if (sectionDvg.SelectedRows.Count > 0)

DataGridViewRow selectedRow = sectionDvg.SelectedRows[0];

var sectionID = selectedRow.Cells["sectionID"].Value;

if (sectionID != null)

try

if (cn.State != ConnectionState.Open)

cn.Open();

string query = "DELETE FROM sections WHERE sectionID = ?";

using (OleDbCommand cmd = new OleDbCommand(query, cn))


{

cmd.Parameters.AddWithValue("?", sectionID);

int rows = cmd.ExecuteNonQuery();

if (rows > 0)

sectionDvg.Rows.Remove(selectedRow);

MessageBox.Show(" deleted ");

else

MessageBox.Show("No section was deleted.");

catch (Exception ex)

MessageBox.Show("Error: " + ex.Message);

finally

cn.Close();

You might also like