Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

ASP .NET Migration and Interoperability

By Exforsys | on April 24, 2005 |
ASP.NET

Before Asp.net invasion there were many other programming languages and technologies on which the dynamic pages were made. In this tutorial I will explain how we can migrate our classic asp application to the modern asp.net application. Most of the components that were written was in visual basic 6 which communicated with the asp application using the COM components.

Using COM Objects in Asp.net

The Asp.net processor understands nearly all the syntax and all the objects that ASP itself supported. Let’s see how you can create a simple ADO Connection object in either an ASP page or an ASP.NET page with this line of code:

cnn = Server.CreateObj("ADODB.Connection");

Not all COM Components can be instantiated in ASP.NET this way. In particular, components that use the Single-Threaded Apartment (STA) threading model will not function properly in ASP.NET pages unless you add a compatibility directive to the page.

@Page aspcompat=true

Let’s see how we can convert an Asp page to an Asp.net page. The is a simple Asp page that communicates with the database and pulls the result and displays it on the screen.

strConn = Provider=SQLOLEDB;Data Source=(local);"&"uid=sa;password=Database=Northwind;" Set cnn = Server.CreateObject("ADODB.Connection");
cnn.Open strConn
strQuery = "SELECT CompanyName FROM Customers"
SET rstCust = cnn.Execute(strQuery)

 

Now Lets see that what we have to do to convert the Classic Page to Modern Asp.net page:

@Page aspcompat=true


object cnn;
object rstCust;
object temp;
string strConn;
string companyName;

strCnn = "Provider=SQLOLEDB;Data Source=(localhost);"

cnn = Server.CreateObject("ADODB.Connection");
cnn.GetType().InvokeMember("Open",BindingFlags.InvokeMethod,null,cnn,new object[]
{ strCnn,Type.Missing,Type.Missing,Type.Missing});

strQuery = "SELECT CompanyName FROM Customers";

while

(!(bool) rstCust.GetType().InvokeMember("EOF",BindingFlags.GetProperty,null,rstCust,new object[] {"CompanyName"});

@Page aspcompat=true object cnn; object rstCust; object temp; string strConn; string companyName; strCnn = "Provider=SQLOLEDB;Data Source=(localhost);" cnn = Server.CreateObject("ADODB.Connection"); cnn.GetType().InvokeMember("Open",BindingFlags.InvokeMethod,null,cnn,new object[] { strCnn,Type.Missing,Type.Missing,Type.Missing}); strQuery = "SELECT CompanyName FROM Customers"; while (!(bool) rstCust.GetType().InvokeMember("EOF",BindingFlags.GetProperty,null,rstCust,new object[] {"CompanyName"});

Working with ADO Recodsets

Recordsets are like dataset with less capability and features. Let’s see some examples of using RecordSets.

To create a recordset containing all of the records in one table of the database, without sorting them:


strSQLQuery = "SELECT * FROM tablename"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3


To create a recordset containing only those records in one table where the field ‘Name’ consists of only the word ‘Fred’:


strSQLQuery = "SELECT * FROM tablename WHERE Name = ‘Fred’"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3


To create a recordset containing all of the records in one table and sort them alphabetically based on the field Name starting at ‘a’:



strSQLQuery = "SELECT * FROM tablename ORDER BY Name ASC"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3

To create a recordset containing all of the records in one table and sort them alphabetically based on the field ‘Name’ starting at ‘z’:

strSQLQuery = "SELECT * FROM tablename ORDER BY Name DESC"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3


If you want to be able to be sure of selecting only one particular record from a database, each table should have a ‘Unique Key’ field – usually a simple auto-incrementing number field. You can then select, update or delete records in the database using this field as the criteria.


strSQLQuery = "SELECT * FROM tablename WHERE RecordID = 15"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3


To retrieve the values of various fields in a Recordset use:


strValue = rs("FieldName")

strValue can of course be any variable name, FieldName is the field name in the table that makes up the recordset. Multiple recordsets can be opened for the same database and/or table – just change the ‘rs’ to whatever name you want to give to each recordset.

Standard SQL queries can be used to update, add or delete records, or create recordsets based on conditions. For example:


strSQLQuery = "DELETE * FROM tablename WHERE Name = ‘Fred’"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3



strSQLQuery = "DELETE * FROM tablename WHERE Name = ‘Fred’ AND Address = ‘Smith St’"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3



strSQLQuery = "DELETE * FROM tablename WHERE Name = ‘Fred’ OR Name = ‘John’"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3



strSQLQuery = "UPDATE tablename SET FieldName1 = " & strValue1 & " WHERE FieldName2 = " & strValue2 & ";"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3



strSQLQuery = "INSERT INTO tablename (FieldName1, FieldName2) VALUES (" & strValue1 & ", " & strValue2 & ")"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQLQuery, conn, 3, 3

Using Platform Invocation Services

Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.

This tutorial shows you what you need to do to be able to call unmanaged DLL functions from C#. The attributes discussed in the tutorial allow you to call these functions and have data types be marshaled correctly.

This is a simple example that shows how you can use the DllImport to import any dll file using C# code.

Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.

This tutorial shows you what you need to do to be able to call unmanaged DLL functions from C#. The attributes discussed in the tutorial allow you to call these functions and have data types be marshaled correctly.

This is a simple example that shows how you can use the DllImport to import any dll file using C# code.

// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();

public static void Main()
{
puts("Test");
_flushall();
}
}


This example shows that how you can use DllImport to produce string.
// Marshal.cs
using System;
using System.Runtime.InteropServices;

class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(
[MarshalAs(UnmanagedType.LPStr)]
string m);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();


public static void Main()
{
puts("Hello World!");
_flushall();
}
}

I hope you liked the tutorial and in the next tutorial we will learn about Session variables which are used to pass values arround.

 

« « MSAS – Creating and Maintaining Calculated Members in Virtual Cubes
MSAS – Defining and Creating Auctions » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • Managing Data with ADO.NET DataSets and C#

    April 8, 2005 - 0 Comment
  • Creating and consuming XML Web Services with C#

    April 14, 2005 - 0 Comment
  • Managing State with ASP.NET and C#

    May 3, 2005 - 0 Comment
  • ASP.NET with C# Training Launch

    February 19, 2005 - 0 Comment
  • Caching in ASP.NET

    May 9, 2005 - 0 Comment
  • Introduction to ASP.NET with C#

    February 20, 2005 - 0 Comment
  • Configuring and Deploying ASP.NET Applications

    May 14, 2005 - 0 Comment
  • ASP.NET with C# Training Course Outline

    February 19, 2005 - 0 Comment
  • Securing ASP.NET Applications with C#

    May 14, 2005 - 0 Comment
  • ASP.NET Web Forms Controls

    February 26, 2005 - 0 Comment
  • Securing ASP.NET Applications with C#

    May 14, 2005 - 0 Comment
  • Configuring and Deploying ASP.NET Applications

    May 14, 2005 - 0 Comment
  • Caching in ASP.NET

    May 9, 2005 - 0 Comment
  • Managing State with ASP.NET and C#

    May 3, 2005 - 0 Comment
  • Creating and consuming XML Web Services with C#

    April 14, 2005 - 0 Comment
  • Managing Data with ADO.NET DataSets and C#

    April 8, 2005 - 0 Comment
  • ASP.NET Using the DataList and Repeater, Datagrid Controls

    March 26, 2005 - 0 Comment
  • Accessing Data with C#

    March 19, 2005 - 0 Comment
  • Using Rich Server Controls with C#

    March 12, 2005 - 0 Comment
  • ASP .NET: Validating User Input with C#

    March 4, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Securing ASP.NET Applications with C#
  • Configuring and Deploying ASP.NET Applications
  • Caching in ASP.NET
  • Managing State with ASP.NET and C#
  • Creating and consuming XML Web Services with C#

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT