Mar.27
TP12 : Les objet dataset et dataAdaper en mode déconnecté
Objectif
Dans ce TP vous allez travailler dans le mode déconnecté avec les objet dataset et dataAdaper.
Questions
Partie serveur :
- Créer la base bibliotheque.
- Dans la base bibliotheque, crée la table : Livre (CodeL, Titre, Auteur, NbExemplaires)
- Remplir la table Livre par les données suivantes :

Partie client :
- Créer l’interface suivante :

- Écrire le code nécessaire qui permet le dataGridView avec les livres de la base de données bibliotheque.
Correction
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace TP13_bib_1
{
public partial class Form1 : Form
{
SqlConnection conn = new SqlConnection("server = DESKTOP-EIALG0J\\SQLEXPRESS; database = bibliotheque; integrated security = SSPI");
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conn;
da.SelectCommand.CommandType = CommandType.Text;
da.SelectCommand.CommandText = "select * from Livre";
da.FillSchema(ds, SchemaType.Source, "Livre");
da.Fill(ds, "Livre");
dataGridView1.DataSource = ds.Tables["Livre"];
}
}
}
