Modifying Data  «Prev  Next»

Lesson 6Direct access to the database with Data Environment
ObjectiveUse the Data Environment object to directly execute commands.

Direct Database Access

You have seen, so far, how to use the Recordset Design Time Control and data bound controls to include database access to theVirtualBookShelf.com project. These controls are easy to implement, taking just a few moments to drag and drop them into a Web page. You can also write script that creates database access in a more direct manner. Perhaps you want, or need, to design a custom interface rather than using that provided by the DTCs in Visual Studio.
Also, by writing your own script, the size of the pages remain smaller and are, therefore, faster to load. You can use the Data Environment (DE) object to create script-based database access. The Data Environment contains the information necessary to access a database and is defined in the Global.asa file. You will recall that you added a DE to a project in Module II and have been using it since then. To script the DE, you need a database connection and one or more command objects. The command objects are used to access a database object. Additionally, the Scripting Object Model (SOM) must be enabled for the page. The SOM is a collection of objects that you use to script the application. Enabling the SOM gives you access to these objects.
The following diagram shows script that creates a DE object and uses it to create a recordset object. It is part of a file called DE.asp.

What is a Custom Interface?

No doubt about it, the Design Time Controls provided by Visual InterDev make it easy to add very nice functionality to your Web pages. There are also other features in Visual InterDev that let you create attractive Web pages, using the Visual InterDev themes for example. Many times, though, you will either want or need to give your Web pages unique functionality and possibly a distinctive "look and feel." To achieve this you will likely write your own code to perform some or all the functions of the Design Time Controls. This way your applications will do precisely what you want, your way.
  • Data Environment (DE) object no longer exists in Visual Studio 2022
    The Data Environment (DE) object has been replaced with more modern alternatives.
    Background on the Data Environment (DE) Object The Data Environment (DE) object was primarily used in Visual Basic 6 (VB6) to provide a graphical way to manage database connections, queries, and reports within applications. It allowed developers to interact with ADO (ActiveX Data Objects) and visually design data-bound applications.
    Modern Alternatives in Visual Studio 2022 Since VB6 and its Data Environment were deprecated long ago, Visual Studio 2022 provides more modern tools for working with databases:
    1. Entity Framework (EF)
      • A widely used Object-Relational Mapper (ORM) for working with databases.
      • Supports Code-First and Database-First approaches.
      • Eliminates the need for manual SQL queries.
      • Alternative to DE: Entity Framework Models replace the old Data Environment object.
    2. Data Tools in Server Explorer
      • Visual Studio provides SQL Server Object Explorer to manage database connections, tables, views, and queries.
      • You can connect to SQL Server, MySQL, PostgreSQL, and other databases directly.
    3. ADO.NET
      • The ADO.NET framework allows developers to programmatically interact with databases using SqlConnection, SqlCommand, and DataAdapters.
      • Alternative to DE: This provides full control over database operations but requires manual coding.
    4. Dataset Designer (Typed Datasets)
      • Provides a drag-and-drop interface for designing database-related components.
      • Still available in Visual Studio but is considered somewhat outdated in favor of Entity Framework.
    5. Azure Data Tools
      • If you are using cloud databases (e.g., Azure SQL), Visual Studio 2022 has integrated tools for managing them.
    Conclusion The "Data Environment (DE) object" from VB6 is not present in Visual Studio 2022. If you need similar functionality, you should use Entity Framework[1], ADO.NET, or SQL Server Data Tools depending on your project needs.

Scripting the Data Environment (DE) Object
SQL Delete statement
Apply, Filter, Sort
  1. This statement creates a reference to the DE object. The PageObject'sCreateDE method is used. The Data Environment is named DE when it is created. Now it can be referenced in this page via the name.
  2. This statement executes the CustTable command object. The CustTable command object returns all the rows in CustTable.
  3. set rs = DE.rsCustTable creates a recordset object to reference the command objects result set, which is all the rows in the table.
  4. This statement uses the recordset object's moveFirst to make sure we're at the first row. Now, recordset object methods can be used to navigate in and manipulate the data. The file DE.asp includes script to display the recordset in an HTML table.

Microsoft Visual InterDev was replaced by Visual Studio 2010, which introduced improved tooling for SharePoint development, among other features . Visual Studio 2010 provided better support for SharePoint, including integrated debugging, flexible deployment tooling, and - improved design support for Business Connectivity Services, Workflow, LINQ to SharePoint, and Visual Web Parts. Key features of Visual Studio 2010 that made it a suitable replacement for Visual InterDev include:
  • Improved SharePoint Development: Enhanced tooling for SharePoint development, including integrated debugging and flexible deployment options.
  • Visual Web Part Designer: A visual designer for creating Web Parts, making it easier to build custom SharePoint components.
  • SharePoint Project Templates: New project templates for SharePoint Foundation, making it easier to get started with SharePoint development.

The next lesson will wrap up this module and include a quiz.
[1]Entity Framework: Entity Framework (EF) is an object-relational mapper (ORM) for .NET that enables developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write.

SEMrush Software