简体   繁体   中英

Delete All row from DataTable in DataSet

I'd like to erase all row in a datatable located in a dataset and then update the DataBase using the method Update() of TableAdapter .

The insert works fine, I put it so you can see what I'm doing. I tried the method Clear() for datatable which was supposed to erase all row but at the moment it does nothing.

I would like to use a kind of SQL query like DELETE * FROM demande; but I dont get how to do it

protected void InsertDemande_Click(object sender, EventArgs e)
{
    //TB = textBox
    //Parsing date (5th row of my dataTable is type date)
    string[] tabdate = TB_date_demande.Text.Split('/');
    DateTime date = new DateTime(int.Parse(tabdate[2]), int.Parse(tabdate[1]), int.Parse(tabdate[0]));

    //In my dataset "Demande", on my table "Demande", i add a new row type "demande" with all good parameters
    ds_Demande.Demande.AddDemandeRow(TB_demande_ID.Text, TB_user_ID.Text, TB_nom_fichier.Text, int.Parse(TB_poids_fichier.Text), date);


    ta_Demande.Update(ds_Demande);//update the database
    LabelResponse.Text = "Ajout effectué avec succès";
    GridViewDemande.DataBind();//refresh gridview
}

protected void ClearTable_Click(object sender, EventArgs e)
{
    ds_Demande.Demande.Clear();//doesn't seem to do anything
    ta_Demande.Update(ds_Demande);
    GridViewDemande.DataBind();
}
// Clear all rows of each table.
ds_Demande.Clear();

// alternatively:
foreach(var row in ds_Demande.Rows) {
   row.Delete();
}  
for(int i = 0; i<ds_Demande.Count; i++)
{
     ds_Demande.Rows[i].Delete();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM