Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Asp and ado

Cnx

SqlConnection cnx = new SqlConnection(@"Data Source=ANDROID\SQLEXPRESS;Initial


Catalog=;Integrated Security=True");

Combobox

public void remplircombo()


{
DataSet ds = new DataSet();

cnx.Open();

SqlDataAdapter sa = new SqlDataAdapter("select * from Lycee", cnx);


sa.Fill(ds, "Lycee");
DropDownList1.DataSource = ds.Tables["Lycee"];
DropDownList1.DataTextField = "nomLycee";
DropDownList1.DataValueField = "idLycee";
DropDownList1.DataBind();
//ado
comboBox2.DisplayMember = "fullname";
comboBox2.ValueMember = "id";

cnx.Close();

Ajouter modifier supprimer

public void CRUD(string query)

SqlCommand cmd = new SqlCommand(query, cnx);

cnx.Open();

cmd.ExecuteNonQuery();

cnx.Close();

}
Login

protected void Button1_Click(object sender, EventArgs e)

string query = "select * from Admin";

SqlCommand cmd = new SqlCommand(query, cnx);

cnx.Open();

SqlDataReader rd = cmd.ExecuteReader();

bool tr = false;

while (rd.Read())

if (TextBox1.Text.Equals(rd[0]) && TextBox2.Text.Equals(rd[1]))

tr = true;

break;

if (tr == true)

Sesions[“id”]=rd[0].tostring();

Response.Redirect("~/WebForm1.aspx");

else

Response.Write("<script>alter('Mot de passe incorrect')</script>");

cnx.Close();

}
XML

DataSet ds = new DataSet();

string query = "select * from personne";

SqlCommand cmd = new SqlCommand(query,cnx);

cnx.Open();

SqlDataReader rd = cmd.ExecuteReader();

ds.Tables.Add("Personne");

ds.Tables["Personne"].Load(rd);

string chm = "";

SaveFileDialog svg = new SaveFileDialog();

svg.Filter = "XML FILES |.*xml";

if (svg.ShowDialog() == DialogResult.OK){

chm = svg.FileName;

ds.WriteXml(chm);

MessageBox.Show("Bien fait");}
Xml in asp

protected void Button6_Click(object sender, EventArgs e)


{

if (cnx.State == ConnectionState.Open)
{
cnx.Close();
}
DataSet ds = new DataSet();
cnx.Open();
string query = "select * from personne";
SqlCommand cmd = new SqlCommand(query, cnx);

SqlDataReader rd = cmd.ExecuteReader();
ds.Tables.Add("p");
ds.Tables["p"].Load(rd);
ds.WriteXml(Server.MapPath("~/Lespersonne.xml"));
cnx.Close();

}
Crystalreport

DataSet1 Ds1 = new DataSet1();

DataSet1TableAdapters.StagiareTableAdapter aa = new
DataSet1TableAdapters.StagiareTableAdapter();

CrystalReport1 cr1 = new CrystalReport1();

cr1.SetDataSource(Ds1);

aa.FillStg(Ds1.Stagiare, nom2);

this.crystalReportViewer1.ReportSource = cr1;

this.crystalReportViewer1.Refresh();

and

CrystalReport1 cr = new CrystalReport1();

a.Da = new System.Data.SqlClient.SqlDataAdapter("select * from personne",a.Cnx);

DataSet1 Ds1 = new DataSet1();

a.Da.Fill(Ds1.personne); cr.SetDataSource(Ds1.Tables[0]);

this.crystalReportViewer1.ReportSource = cr;

this.crystalReportViewer1.Refresh();
Navigation and recherché

public void RPSPRD(string query)

this.dataGridView1.Rows.Clear();

SqlCommand cmd = new SqlCommand(query, cnx);

cnx.Open();

SqlDataReader rd = cmd.ExecuteReader();

if (rd.HasRows){

rd.Read();

this.dataGridView1.Rows.Add(rd[0], rd[1], rd[2], rd[3]);

textBox1.Text = "" + rd[0];

textBox2.Text = "" + rd[1];

textBox3.Text = "" + rd[2];

textBox4.Text = "" + rd[3];

cnx.Close();

Recherche

RPSPRD("select * from Personne where ID=" + textBox1.Text+ "");

Premier

RPSPRD("select top 1 * from Personne ORDER BY ID asc");

Dernier

RPSPRD("select top 1 * from Personne ORDER BY ID desc");

Suivant

RPSPRD("select top 1 * from Personne where id > " + textBox1.Text + " order by ID asc");

Precedent

RPSPRD("select top 1 * from Personne where id < " + textBox1.Text + " order by ID desc");
Afficher table

public void AFFICHETABLE()

{this.dataGridView1.Rows.Clear();

string query = "select * from Personne";

SqlCommand cmd = new SqlCommand(query, cnx);

cnx.Open();

SqlDataReader rd = cmd.ExecuteReader();

if (rd.HasRows)

while (rd.Read())

this.dataGridView1.Rows.Add(rd[0], rd[1], rd[2], rd[3]);

cnx.Close();

In asp
public void RemplirGrid()
{
DataTable dt = new DataTable();
string query = "select * from ";
SqlCommand cmd = new SqlCommand(query, cnx);
if (cnx.State == ConnectionState.Open)
{
cnx.Close();
}
cnx.Open();
SqlDataReader rd = cmd.ExecuteReader();
dt.Load(rd);
GridView1.DataSource = dt;
GridView1.DataBind();

cnx.Close();

}
Authentication
protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] == null)
{
Response.Redirect("~/Connexion.aspx");
}
if (!Page.IsPostBack)
{
remplircombo();
}
}

Calculer nbr ligne

protected void Button1_Click(object sender, EventArgs e)


{
int nombre;
string query = "select count(*) from Detail_Demande “;
SqlCommand cmd = new SqlCommand(query, cnx);
cnx.Open();
nombre = (int)cmd.ExecuteScalar();
cnx.Close();
}

You might also like