The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ADO.NET Tips & Tricks - Part I

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tim Sneath

Posts: 395
Nickname: timsneath
Registered: Aug, 2003

Tim Sneath is a .NET developer for Microsoft in the UK.
ADO.NET Tips & Tricks - Part I Posted: Aug 20, 2003 11:35 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Tim Sneath.
Original Post: ADO.NET Tips & Tricks - Part I
Feed Title: Tim Sneath's Blog
Feed URL: /msdnerror.htm?aspxerrorpath=/tims/Rss.aspx
Feed Description: Random mumblings on Microsoft, .NET, and other topics.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Tim Sneath
Latest Posts From Tim Sneath's Blog

Advertisement

This is either (a) the start of an occasional series discussing ways to get the most out of ADO.NET, or (b) Tim writing up a series of notes he made while reading Microsoft ADO.NET Core Reference - you decide!

  • If you're trying to create an OLE DB connection string to use with an OleDbConnection object, create an empty file with a .UDL extension on the desktop (e.g. copy nul conn.udl), and then double-click on it. Use the user interface to configure the connection, and then open the .UDL file up in Notepad. Bingo - a fully-populated connection string!
  • Details of all the provider-specific connection properties can be found in the MDAC SDK.
  • Rather than creating a new SqlCommand object and passing it a connection as a parameter to the constructor, why not simply call the SqlConnection.CreateCommand() method for the sake of simplicity? The C# using keyword can be applied to this to allow the object to be auto-disposed when finished with.
  • Speed up the performance of DataReader queries by (i) using ordinals to specify the column name (you can identify the specific ordinal with the GetOrdinal() method), and (ii) using a type-specific GetX() method rather than an indexer to retrieve the column contents. Thus myReader.GetString(0) rather than myReader["custName"].
  • When a row is updated, the original version is maintained in a cache. You can view each version using row["col", DataRowVersion.Current] or row["col", DataRowVersion.Original].
  • You can add your own custom property information to a dataset using the ExtendedProperties property. This returns a PropertyCollection object, so you can read and write properties as follows:
       ds.ExtendedProperties.Add("LastUpdated", "Value1");
       Console.WriteLine(ds.ExtendedProperties["LastUpdated"]);
  • You can filter a table with a SQL WHERE clause. Simply add it to the table with similar syntax to the following:
       foreach (DataRow row in tbl.Select("Country='UK' AND City = 'Nottingham'"))
          Console.WriteLine(row["CompanyName"]);
  • The DataTable.Select() method contains an overload to support sort orders also:
       tbl.Select("CompanyName LIKE 'Micro%'", "Country DESC")
  • You can create a DataView object using similar syntax; this can be bound to a Windows or web form control:
       vue = new DataView(tbl, criteria, sortOrder, rowState);

More soon...

Read: ADO.NET Tips & Tricks - Part I

Topic: Web Services Browser? Previous Topic   Next Topic Topic: More Confusion on WinFS

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use