How to update a dataset

前端 未结 2 1136
太阳男子
太阳男子 2021-01-15 05:24

In my project, there are two textBoxes, txtName and txtPopulation and a Button, btnClick. whenever the user clicks btnClick

2条回答
  •  感情败类
    2021-01-15 05:49

    You need to call .AcceptChanges() on your DataTable so your changes are committed to the collection, like this:

    for (int intCount = 0; intCount < dsDetails.Tables[0].Rows.Count; intCount++)
    {
        if (lblCountryName.Text.Equals(dsDetails.Tables[0].Rows[intCount][0].ToString()))
        {
            dsDetails.Tables[0].Rows[intCount][3] = txtPopulation.Text;
        }
    }  
    
    dsDetails.Tables[0].AcceptChanges();
    

    Using select row filter

    You can target your column by using the .Select row filter, like this:

    foreach (DataRow row in dsDetails.Tables[0].Select("Name = '" + txtName.Text + "'"))
    {
        row[3] = txtPopulation.Text;
    }
    
    dsDetails.Tables[0].AcceptChanges();
    

提交回复
热议问题