LoadOption.OverwriteChanges - Functionlaity [modified]
-
<I have written code to test the SqlDataAdaptor's LoadOpton functionality for LoadOption.OverwriteChanges. But the code that i written is not working.. Values are not getting overwritten Here are the values which i am getting when i run the code ***Default*** Original Value: Chai, Current Value: Chai ***Values Before Reload*** Original Value: Chai, Current Value: Coffee ***LoadOption.OverwriteChanges;*** Original Value: Chai, Current Value: Coffee Expected results are ***Default*** Original Value: Chai, Current Value: Chai ***Values Before Reload*** Original Value: Chai, Current Value: Coffee ***LoadOption.OverwriteChanges;*** Original Value: Chai, Current Value: Chai Here is the code which i have written. i scratched my head almost 2hrs couln't get any answer. Please let me know where i have done wrong.. protected void Page_Load(object sender, EventArgs e) { DataSet poductsDS = new DataSet(); string query = "Select ProductName, UnitPrice from Products"; string _conStr = System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString; SqlDataAdapter da = new SqlDataAdapter(query,_conStr); da.Fill(productsDS); Display(productsDS, "Default"); //updating table filed values DataRow row = productsDS.Tables[0].Rows[0]; row["ProductName"] = "Coffee"; Display(productsDS, "Values Before Reload"); //Reloading SqlDataAdapter da2 = new SqlDataAdapter(query,_conStr); da2.FillLoadOption = LoadOption.OverwriteChanges; da2.Fill(productsDS); Display(productsDS, "LoadOption.OverwriteChanges;"); } private void Display(DataSet ds, string Heading) { Response.Write("***" + Heading + "***"); Response.Write("<br/>"); DataTable table = ds.Tables[0]; DataRow row = table.Rows[0]; Response.Write(string.Format("Original Value: {0}, Current Value: {1}", row[0, DataRowVersion.Original].ToString(), row[0, DataRowVersion.Current].ToString())); Response.Write("<br/>"); Response.Write("<br/>"); }
Satish
modified on Sunday, October 4, 2009 5:09 AM