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 Gst_Stg_insertion
{
public partial class Insert : Form
{
public Insert()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlDataAdapter sqlda = new SqlDataAdapter("select * from stagiaire", "data source=.;initial catalog = ecole; integrated security = true");
private void Form1_Load(object sender, EventArgs e)
{
sqlda.Fill(ds, "Stagiaire");
MessageBox.Show(ds.Tables["Stagiaire"].Rows.Count.ToString());
}
private Boolean Rechercher(int co)
{
Boolean b = false;
int i;
DataRow dr;
for (i = 0; i < ds.Tables["Stagiaire"].Rows.Count - 1; i++)
{
dr = ds.Tables["Stagiaire"].Rows[i];
if (dr[0].Equals(co) == true) b = true;
}
return b;
}
private void btnAjou_Click(object sender, EventArgs e)
{
DataRow drw;
Boolean b = Rechercher(int.Parse(this.txtCode.Text));
if (b == false )
{
drw = ds.Tables["Stagiaire"].NewRow();
drw[0] = int.Parse(txtCode.Text);
drw[1] = this.txtNom.Text;
drw[2] = this.txtPrenom.Text;
drw[3] = this.txtcode_sp.Text;
ds.Tables["Stagiaire"].Rows.Add(drw);
MessageBox.Show("Ajoute(e) avec Success");
}
else
MessageBox.Show("exist");
}
}
}