Ejemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //test if page is being loaded for the first time do database is not getting hit during every request.
     if (!Page.IsPostBack)
     {
         //call BindGridView method on dsAddress objec. if page is loaded for the first time.
         dsAddress addressSet = BindGridView();
     }
 }
Ejemplo n.º 2
0
    public dsAddress FindAddress(string Path, int AddressId)
    {
        //create a new OleDbConnection objec and pass in connection string.
        OleDbConnection sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + "");

        //create a SQL query to search for AddressId.  Convert the argument that is passed in to a string.
        string           sql   = "select * from tblAddressBook WHERE AddressId = " + Convert.ToString(AddressId);
        OleDbDataAdapter sqlDA = new OleDbDataAdapter(sql, sqlConn);

        //create a new dsAddress object and fill it with the records returned from the sql query.
        dsAddress ds = new dsAddress();

        sqlDA.Fill(ds.tblAddressBook);

        return(ds);
    }
Ejemplo n.º 3
0
    private dsAddress BindGridView()
    {
        //TempPath to hold the location of the database.
        string TempPath;

        TempPath = Server.MapPath("App_Data/AddressBook.mdb");

        //instantiate new clsDataLayer object.
        clsDataLayer oDataLayer = new clsDataLayer();

        //call the GetAllAddresses method and pass in TempPath for the argument.  returns a data set to be stroed in myAddressSet.
        dsAddress myAddressSet = oDataLayer.GetAllAddresses(TempPath);

        //assign the data source to the grid view from the data set.
        gvAddresses.DataSource = myAddressSet.tblAddressBook;

        //bind the grid view to the data source.
        gvAddresses.DataBind();

        //return the data set.
        return(myAddressSet);
    }
Ejemplo n.º 4
0
    //GetAllAddresses() accepts the Path of the Access db and returns a data set.
    public dsAddress GetAllAddresses(string Path)
    {
        //create the variables that will hold the data set, connection string, and query.
        dsAddress        DS;
        OleDbConnection  sqlConn;
        OleDbDataAdapter sqlDA;

        //create new OleDbConnection object that holds the connection string.
        sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" + Path);

        //create new OleDbDataAdapter object that contains query to return all records from tblAddressBook.
        sqlDA = new OleDbDataAdapter("select * from tblAddressBook;", sqlConn);

        //instantiate new dsAddress object.
        DS = new dsAddress();

        //calls the Fill() method to add/refresh records in the data set to match the data source.
        sqlDA.Fill(DS.tblAddressBook);

        //returns the dataset object.
        return(DS);
    }