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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace TestAffichageDonneesDivalto
{
public partial class COMMANDE_LISTE : Form
{
public COMMANDE_LISTE()
{
InitializeComponent();
}
private void COMMANDE_LISTE_Load(object sender, EventArgs e)
{
// Déclaration des variables
string strConnexion;
string strRequete;
SqlConnection oConnection;
SqlCommand oCommand;
SqlDataReader oReader;
DataGridViewRow LigneInseree;
// Création des colonnes de la table
TableCommandesClient.Columns.Add("PIDT", "Date");
TableCommandesClient.Columns.Add("PINO", "Pièce no");
TableCommandesClient.Columns.Add("CE4", "Etat");
// Chaîne de connection à la base de données
strConnexion = "Data Source=SRVDIVALTO2;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False; database=ERPASPTEST";
// Requête de sélection des commandes clients
strRequete = "SELECT ENT.PIDT AS Date, ENT.PINO As 'Pièce no', ENT.CE4 AS 'Etat' from ENT where ENT.TICOD='C' AND ENT.PICOD=2";
try
{
// Initialisation de la connexion à la base de données
oConnection = new SqlConnection(strConnexion);
// Création de l'objet commande qui permettra d'exécuter la requête
oCommand = new SqlCommand(strRequete, oConnection);
// Ouverture de la connexion à la base de données
oConnection.Open();
// Exécution de la requête de sélection des commandes client
oReader = oCommand.ExecuteReader();
do
{
while (oReader.Read())
{
// ajout de la commande client dans la table
LigneInseree = new DataGridViewRow();//(DataGridViewRow)TableCommandesClient.RowTemplate.Clone();
LigneInseree.Cells[0].Value = oReader[1];
LigneInseree.Cells[1].Value = oReader[2];
LigneInseree.Cells[2].Value = oReader[3];
TableCommandesClient.Rows.Add(LigneInseree);
}
}
while (oReader.NextResult());
// Fermeture du DataReader
oReader.Close();
// Fermeture de la connexion
oConnection.Close();
}
catch (Exception MonException)
{
Console.WriteLine("L'erreur suivante a été rencontrée :" + MonException.Message);
}
}
}
} |
Partager