ADO Database ASP.Net

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Runtime.Serialization.Formatters.Binary" %>
<%@ Import Namespace="System.Web.Configuration" %>

    void Page_Load(object sender, System.EventArgs e)
    {
        DataSet categories = GetCategories();
        string fileName = Server.MapPath("App_Data/Data.dat");
        using (FileStream stream = new FileStream(fileName, FileMode.Create))
        {
            categories.RemotingFormat = SerializationFormat.Binary;
            BinaryFormatter format = new BinaryFormatter();
            format.Serialize(stream, categories);  
            stream.Flush();          
        }
        Response.Write("File written successfully");    
    }
    
    void btnReadFromFile_Click(object sender, EventArgs e)
    {        
        string fileName = Server.MapPath("App_Data/Data.dat");
        using (FileStream stream = new FileStream(fileName, FileMode.Open))
        {            
            BinaryFormatter format = new BinaryFormatter();
            DataSet categoriesFromFile = (DataSet) format.Deserialize(stream);            
            gridCategories.DataSource = categoriesFromFile.Tables[0].DefaultView;
            gridCategories.DataBind();
        }
    }
    
    DataSet GetCategories()
    {
        string connString = WebConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
        string sql = "Select * from Production.ProductSubcategory";
        DataSet categories = new DataSet("Categories");
        using (SqlConnection connection = new SqlConnection(connString))
        {
          SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
          adapter.Fill(categories);
        }
        return categories;
      }   



  DataSet Serialization and Deserialization using Binary Format



    

                        ID="btnReadFromFile" 
                  OnClick="btnReadFromFile_Click"
                  Text="Read the Data from file" />
        
                          runat="server" 
                    AutoGenerateColumns="False" 
                    CellPadding="4" 
                    HeaderStyle-BackColor="blue" 
                    HeaderStyle-ForeColor="White" 
                    HeaderStyle-HorizontalAlign="Center" 
                    HeaderStyle-Font-Bold="True">