To Lecture Notes

IT130 Notes -- 5/18/09

Review Questions

  1. List the five ASP.Net data objects needed to display data from a database table in a DataGrid control.
    Ans: Connection   DataAdapter   Command   DataSet   DataGrid
     
  2. Explain how to use the data objects in the previous example to display the data from a table in an Access database in a DataGrid control. Ans:
    // Create and configure connection:
    OleDbConnection c = new OleDbConnection( );
    c.ConnectionString = 
        Provider=Microsoft.Jet.OLEDB.4.0; +
        Data Source=e:\\ectserver\\ssmith\\Database\\groceries.mdb;
    
    // Create and configure SelectCommand object.
    OleDbCommand sc = c.CreateCommand( );
    sc.Commandclass = Commandclass.Text;
    sc.CommandText = ddlSelect.SelectedValue;
    
    // Create and configure DataAdapter object.
    OleDbDataAdapter da = new OleDbDataAdapter( );
    da.SelectCommand = sc;
    
    // Create and populate DataSet object.
    DataSet ds = new DataSet( );
    int n = da.Fill(ds, Groceries);
    
    // Display data in DataGrid object.
    dgGroceries.DataSource = ds;
    dgGroceries.DataBind( );
    
  3. Write an sql statement that outputs rows from the Person table. Select the rows where Age is given in the textbox txtAge and Gender is given in the RadioButtonList control radGender. Ans:
    sql = SELECT * FROM Persons  +
          WHERE Age =  + txtAge.Text + 
           AND Gender = ' + ddmGender.SelectedValue + ';;
    
  4. Use Visual Studio to implement your answer to Problem 7. Use an AccessDataSource Control to manage the database objects.
    Ans: See Using an AccessDataSource Control in Visual Studio. Also see Example 56 (access-control.aspx Example).

 

Tables with Visual Studio

 

Using an ArrayList Collection

 

More Database Examples