slt,
Sans vouloir être désagréable, comment vous pouvez être tous en fin d'études et ne pas savoir faire sa..?
Vous vous imaginez allez a un entretien devant un patron et lui ire que vous ne savez pas faire sa..?
Bon bref..
Example pour SQL Server :
Creer un connection:
public class session
{
string currentPath = Application.StartupPath;
public SqlCeConnection Iconnection;
public session()
{
Iconnection = new SqlCeConnection("data source=" + currentPath + "\\MyDatabase#1.sdf");
}
public SqlCeConnection connection()
{
if(Iconnection.State.ToString() != "Open")
Iconnection.Open();
return Iconnection;
}
public void deconnection()
{
if (Iconnection.State.ToString() == "Open")
Iconnection.Close();
}
}
Exemple pour remplir un gridview depuis les donnée du DB..j'ose espérer que tu sera t'adapter..
public DataTable GamesGridGetAll()
{
DataTable Table = new DataTable();
List<ObjectLb.ObjectClass.Games> obj = getAll();
Table.Columns.Add(new DataColumn("Title"));
Table.Columns.Add(new DataColumn("Genre"));
Table.Columns.Add(new DataColumn("size"));
Table.Columns.Add(new DataColumn("plateform"));
Table.Columns.Add(new DataColumn("editor"));
Table.Columns.Add(new DataColumn("developer"));
Table.Columns.Add(new DataColumn("format"));
Table.Columns.Add(new DataColumn("language"));
foreach (ObjectLb.ObjectClass.Games myObject in obj)
{
Table.Rows.Add(myObject.Title, myObject.Genre, myObject.Size, myObject.Plateform, myObject.Editor, myObject.Developer, myObject.Format, myObject.Language);
}
return Table;
}
/// <summary>
/// Bind all data in object and return object list
/// </summary>
/// <returns></returns>
public List<ObjectLb.ObjectClass.Games> getAll()
{
ObjectLb.ObjectClass.Games _myObjectGames;
List<ObjectLb.ObjectClass.Games> _myObjectListTemp = new List<ObjectLb.ObjectClass.Games>(); ;
_myObjectGames = new ObjectLb.ObjectClass.Games();
SqlCeCommand cmd = new SqlCeCommand("SELECT id, title, genre, size, plateform, editor, developer, format, language FROM games;", _Session.connection());
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
_myObjectGames = new ObjectLb.ObjectClass.Games();
_myObjectListTemp.Add(_myObjectGames);
_myObjectGames.Title = reader.GetString(1);
_myObjectGames.Genre = reader.GetString(2);
_myObjectGames.Size = reader.GetString(3) + " Giga";
_myObjectGames.Plateform = reader.GetString(4);
_myObjectGames.Editor = reader.GetString(5);
_myObjectGames.Developer = reader.GetString(6);
_myObjectGames.Format = reader.GetString(7);
_myObjectGames.Language = reader.GetString(8);
}
reader.Close();
return _myObjectListTemp;
}
Et ce qui appel tous sa.
.void loadDataTable(int IndexTable)
{
switch (IndexTable)
{
case 1:
this.Cursor = Cursors.WaitCursor;
DatabaseLb.RequestClass.Movies ObjMovies = new DatabaseLb.RequestClass.Movies();
_Session.connection();
grdTableFilms.DataSource = ObjMovies.MoviesGridGetAll();
_Session.deconnection();
this.Cursor = Cursors.Default;
break;.....
A toi de t'adapter..(Indice..Tout est dans le reader..)
Just enjoy it..