Nigel Whitworth's Development Site

You are currently not logged in.

ADO.NET

Whereas ADO was designed so that it could be used in both connected and disconnected modes. ADO.NET has been designed primarily for disconnected recordsets. Although ADO is a COM based interface, it is still accessible from VB.NET but not recommended. ADO.NET has been split into three distinct groups, SQL Server, Oracle and OLEDB. Any database structure that does not fall into the first two, falls into the third which includes Sybase and Access. ADO which utilises ODBC principles in other words, you code using one database and it can be exported and used on another, ADO.NET breaks that mould. Enough gripes, back to the information. Below is a example of how you would access records from an access database using ADO.NET

    Imports System.Data.OleDb

    dim objParam as OleDbParameter
    dim objCmd as OleDbCommand
    dim ObjDr as OleDbDataReader
    dim objDA as OleDbDataAdapter
    dim objDS as DataSet
    dim objRow as DataRow
		 
    try
        objConn = new OleDbConnection(strConnection)            ' Connection string as you would in ADO
        objConn.Open()
				
        objCmd = New OleDbCommand(strQuery,objConn)
        objCmd.CommandType = CommandType.StoredProcedure
        
        objDA = new OleDbDataAdapter()

        objDA.SelectCommand = objCmd
				
        objParam = new OleDbParameter()
        with objParam
            .ParameterName="City"
            .OleDbType = oleDbType.varchar
            .Size = 50
            .Value = "Derby"
        end with
				
        objDA.SelectCommand.Parameters.add(objParam)

        objDS = new DataSet()

        objDA.Fill(objDS,"Records")
	
        for each objRow in objDS.Tables("Records").Rows
            Console.writeLine("County)
        Next
    Catch e as exception
        console.writeLine(e.message)
    Finally
        ' Clear and close all objects.
    End Try
For queries that are Delete and Update operations. You would replace SelectCommand with DeleteCommand or UpdateCommand. From the line objDS = new Dataset() to Catch, you would put
         x = objDA.UpdateCommand.ExecuteNonQuery()
In the variable x will contain the number of records affected by the operation.


If you intend to vote or make a comment, please enter the security code. CODE

Make a comment

*Comments are the views of individuals, they may or may not be correct.
All comments are reviewed and accepted or rejected.
If you give an email address, you will be sent an email when someone makes a comment on this page.*

Name :
Email :
Comments :


Only name and Code is compulsory.