using System; using System.Text; using System.Data.SqlClient; using System.Data; namespace WindowsFormsApplication1 { public class DataAccess { public SqlConnection Conn { get; } public DataTable Table { get; set; } public SqlDataAdapter DataAdapter { get; set; } public SqlDataReader DataReader { get; set; } public SqlCommandBuilder CommandBuilder { get; set; } public DataAcces() { this.Conn= new SqlConnection("server=.;database=Utilisateur;integrated security=true"); } public void GetData(string table) { this.DataAdapter = new SqlDataAdapter("select * from" + table, this.Conn); this.DataTable = new DataTable(); this.DataAdapter.Fill(this.DataTable); this.CommandBuilder = new SqlCommandBuilder(this.DataTable); } } } }
using System; using System.Text; using System.Data.SqlClient; using System.Data; namespace WindowsFormsApplication1 { class utili { private DataAcces _access = null; private DataAcces Access { get {if(this._access == null) { this._access = new DataAccess() this._access.GetData("utili"); } return this._access; } public int Id { get; set; } public string Nom { get; set; } public string Sexe { get; set; } public DateTime Date { get; set; } public utili(int id, string nom,string sexe,DateTime date) { this.Id = id; this.Nom = nom; this.Sexe = sexe; } public void AddToTable(DateTime date) { DataRow row = new DataRow() row[0]= this.Id; row[1] = this.Nom; row[2] = this.Sexe; row[3] = date; this.Access.Table.Rows.Add(row); } public void Validate() { this.Access.DataAdapter.Update(this.Access.Table); } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question