affichage sous forme de table
Bonjour à tous 8-)
Je suis un débutant en C# mais pas en POO. En fait je travaille sur un projet d'automatisation des tableaux de bord de la banque dans la quelle je bosse.
J'ai une table nommée ACTIVITE dans ma base oracle, j'ai fait un simple select sur C# (un retour String) et j'ai affiché le resultat dans un label.text (ASP). Ceci marche à merveille :D
Hélas :cry: , l'affichage n'est pas bon du tout, en fait j'aimerai avoir un affichage sous forme de table alors j'ai écrit cet algorithme:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Oracle.DataAccess.Client;
using System.Text;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "DATA SOURCE=bdpbc;PERSIST SECURITY INFO=True;USER ID=bdpbcadmin;PASSWORD=bdpbcadmin123";
Label1.Text =ExecuteSelect(connectionString, "select * from ACTIVITE ");
}
StringBuilder ExecuteSelect(string connectionString, string requete)
{
try
{
OracleConnection connexion = new OracleConnection(connectionString);
// ouverture connexion
connexion.Open();
// exécute sqlCommand avec requête select
OracleCommand sqlCommand = new OracleCommand(requete,connexion);
OracleDataReader reader = sqlCommand.ExecuteReader();
StringBuilder ligne = new StringBuilder(); //constructeur d'objet
int i;
for (i = 0; i < reader.FieldCount - 1; i++)
{
ligne.Append(reader.GetName(i)).Append(",");
}
Console.WriteLine("\n{0}\n{1}\n{2}\n", "".Padleft(ligne.Length, '-'), ligne, "".PadLeft(ligne.Length, '-'));
while (reader.Read()) {
ligne = new StringBuilder();
for (i = 0; i < reader.FieldCount; i++) {
ligne.Append(reader[i].ToString()).Append(" ");
}
Console.WriteLine(ligne);
}
reader.Close();
sqlCommand.Dispose();
connexion.Close();
}
catch (Exception ex)
{
msg d'erreur
Console.WriteLine("Erreur d'accès à la base de données (" + ex.Message + ")");
}
return ligne;
}
}
} |
SVP quelqu'un peut me proposer une solution, :(
A++ les amis