Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jag scemo :p
- //classe
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data;
- using System.Data.OleDb;
- namespace StudentiVoti
- {
- class DAL
- {
- private OleDbConnection _conn;
- public DAL()
- {
- string cns = GetConnectionString();
- _conn = new OleDbConnection(cns);
- _conn.Open();
- }
- private string GetConnectionString()
- {
- string dbDirPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- string cns = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\M_inf3.Quarta\Desktop\StudentiVoti.accdb";
- return cns;
- }
- public DataTable StudentiElenco(string CognomeFiltro)
- {
- DataTable tbl = new DataTable();
- string qry = "SELECT * FROM Studenti WHERE Cognome=?";
- OleDbCommand cmd = new OleDbCommand(qry, _conn);
- cmd.Parameters.AddWithValue("?", CognomeFiltro);
- OleDbDataAdapter dad = new OleDbDataAdapter(cmd);
- dad.Fill(tbl);
- _conn.Close();
- return tbl;
- }
- public DataTable VotiElenco(string IDStudente)
- {
- DataTable tbl = new DataTable();
- string qry = "SELECT * FROM Voti WHERE IDStudente=?";
- OleDbCommand cmd = new OleDbCommand(qry, _conn);
- cmd.Parameters.AddWithValue("?", IDStudente);
- OleDbDataAdapter dad = new OleDbDataAdapter(cmd);
- dad.Fill(tbl);
- _conn.Close();
- return tbl;
- }
- }
- }
- //classe form
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace StudentiVoti
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- DAL c = new DAL();
- dgb1.DataSource = c.VotiElenco(comboBox1.Text);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- DAL c = new DAL();
- dgb2.DataSource = c.StudentiElenco(txtCognome.Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment