FillLoadOption property of the Fill method on data adapters. : SqlDataAdapter « ADO.net Database « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
    Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Fill Load Options</title>
</head>
<body>
    <div id="pageContent">
        <form id="form1" runat="server">
            <div>
                <table>
                    <tr>
                        <td><b>&nbsp;</b></td>
                        <td><b>ORIGINAL</b></td>
                        <td><b>CURRENT</b></td>
                    </tr>
                    <tr>
                        <td><b>BEFORE</b></td>
                        <td>
                            <asp:Label runat="server" ID="BeforeLoadOrig" text="Michela" />
                        </td>
                        <td>
                            <asp:Label runat="server" ID="BeforeLoadCurr" text="Sylvia" />
                        </td>
                    </tr>
                    <tr>
                        <td><b>AFTER</b></td>
                        <td>
                            <asp:Label runat="server" ID="AfterLoadOrig" />
                        </td>
                        <td>
                            <asp:Label runat="server" ID="AfterLoadCurr" />
                        </td>
                    </tr>
                </table>
                <br /><br />
                <asp:DropDownList ID="LoadOptionList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="LoadOptions_SelectedIndexChanged">
                    <asp:ListItem>PreserveChanges</asp:ListItem>
                    <asp:ListItem>OverwriteChanges</asp:ListItem>
                    <asp:ListItem>Upsert</asp:ListItem>
                </asp:DropDownList>
                <asp:Button ID="RefreshButton" runat="server" Text="Load" OnClick="RefreshButton_Click" />
                <hr />
            </div>
        </form>
    </div>
</body>
</html>


File: Default.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class Default : System.Web.UI.Page
{
  private DataSet _data;
  private string SelectCmd = "SELECT employeeid, firstname, lastname FROM employees";

  private void InitDataSet()
  {
    _data = new DataSet();    
    SqlDataAdapter adapter = new SqlDataAdapter(SelectCmd,ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
    adapter.Fill(_data);

    DataTable t = _data.Tables[0];
    DataRow r = t.Rows[0];
    r["firstname"] = "Michela";
    r.AcceptChanges();

    t = _data.Tables[0];
    r = t.Rows[0];
    r["firstname"] = "Sylvia";
  }

  protected void RefreshButton_Click(object sender, EventArgs e)
  {
    InitDataSet();

    DataRow row = _data.Tables[0].Rows[0];

    BeforeLoadOrig.Text = row["firstname", DataRowVersion.Original].ToString();
    BeforeLoadCurr.Text = row["firstname", DataRowVersion.Current].ToString();

    SqlDataAdapter adapter = new SqlDataAdapter(
      SelectCmd,
            ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);

    adapter.FillLoadOption = (LoadOption)Enum.Parse(typeof(LoadOption), LoadOptionList.SelectedValue);
    adapter.Fill(_data);

    AfterLoadOrig.Text = row["firstname", DataRowVersion.Original].ToString();
    AfterLoadCurr.Text = row["firstname", DataRowVersion.Current].ToString();
  }


  protected void LoadOptions_SelectedIndexChanged(object sender, EventArgs e)
  {
    AfterLoadOrig.Text = "";
    AfterLoadCurr.Text = "";
  }
}








18.5.SqlDataAdapter
18.5.1.Inline binding DataSet
18.5.2.Using an object of SqlDataAdapter to fill a DataTable (C#)
18.5.3.Using an object of SqlDataAdapter to fill a DataTable (VB)
18.5.4.FillLoadOption property of the Fill method on data adapters.