How To Ideas | How To Articles | How To Tutorials


0

How To Edit Data In Untyped DataSet In ASP.NET


Dataset is one of those controls which programmers use most of the time for binding data to any of the Data Binding Control. When you fetch data from SQL Server in Dataset, then you can edit the fetched data before binding it to any of the Data Binding control. I have already discussed the same topic for Type Dataset over here. Using this approach your actual data in the Database will not change but the data which will be shown to user in browser.

Instructions:

  1. Before editing data in DataSet, you need to have data in a DataSet instance. Using following code, I fetched all the data from [abc] Table into DataSet instance ds.

    SqlConnection con = new SqlConnection();
    con.ConnectionString = @"Provide your own connection string here";
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "select * from [abc]";
    cmd.Connection = con;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);

    and here is the output in browser, If I bind this DataSet to any Data Binding control(Repeater used here)
    Output In Browser Without Editing Data In DataSet

  2. In the above image, I want to change the value for Address column ( [Eadd] – column name or 2 index) in 2nd row ( i.e index 1), then I can do so using any the following code.

    ds.Tables[0].Rows[1]["Eadd"] = "New Value"; //Eadd is the actual column name of Address column in Database

    or

    ds.Tables[0].Rows[1][2] = "New Value";

  3. Here is the output in Browser after using any of the above statement for editing data in DataSet.
    Output In Browser After Editing Data In DataSet

Incoming search terms:

  • how to edit the details in asp net (1)
Filed in: ASP.NET Tags: , , , , , , , ,

Leave a Reply

Submit Comment



© 0042 How To Ideas. All rights reserved.
Proudly designed by Theme Junkie.