Migrating ADO.NET Codeby James Culshaw
With the release of the new .NET Visual Studio (or VS.NET SDK Beta 2), Microsoft has made some fundamental changes. One area that has been changed is ADO.NET. The purpose of this article is to illustrate some of these changes and allow you to move your ADO code from Beta 1 to Beta 2 as simply as possible. All examples in this article are in C#.
The first change that Microsoft has made is to the namespace that you import. In Beta 1 you would use the following:
In Beta 2 you now use the following:
Coupled with the namespace change, the class names have changes as well. The following table lists some of the Beta 1 class names and their new Beta 2 class names:
|Beta 1||Beta 2|
As you can see, the change has been to replace the leading ADO with OleDb (the case is important).
OleDbCommand object no longer has the
Execute method. This has been
replaced by the
In Beta 1, to populate a
DataReader object from the
Command object, you would write the following:
In Beta 2, you would now issue the following:
OleDbDataReader drResults = cmRunProc.ExecuteReader();
The fundamental change is that you no longer have to pass a
DataReader object into the
Command object to be populated. The
Command object now creates and returns the populated
When invoking the
ExecuteReader method, you can now provide a
CommandBehavior parameter. One use of this is to close the associated connection when the associated
DataReader object is closed.
OleDbDataReader drResults =
Another change to the
Command object is that the
ActiveConnection property has been renamed to
Connection. To associate a
Connection object with a
Command object in Beta 1, the syntax was as follows:
cmRunProc.ActiveConnection = cnDB;
In Beta 2, the syntax is now:
cmRunProc.Connection = cnDB;
That's it. You have now learned how to move your ADO code from VS.NET Beta 1 to Beta 2 using C#.
James Culshaw is a certified MCP developer and holds a BSc (Honors).
Return to the .NET DevCenter.