Microsoft KB Archive/317952

= DOC: Corrections to Visual C# .NET Samples in &quot;Sample .NET Data Provider&quot; Documentation =

Article ID: 317952

Article Last Modified on 3/7/2002

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft Visual C# .NET 2002 Standard Edition

-



This article was previously published under Q317952



SUMMARY
When you try to compile the Visual C# .NET sample code that is included in the Sample .NET Data Provider topic in the Microsoft .NET Framework Software Development Kit (SDK) documentation, you receive the following error messages:

TemplateConnection.cs(6,16): error CS0535: 'DotNetDataProviderTemplate.TemplateConnection' does not implement interface member 'System.IDisposable.Dispose'

-and-

TemplateCommand.cs(6,16): error CS0536: 'DotNetDataProviderTemplate.TemplateCommand' does not implement interface member 'System.Data.IDbCommand.CreateParameter'. 'DotNetDataProviderTemplate.TemplateCommand.CreateParameter' is either static, not public, or has the wrong return type.

-and-

TemplateCommand.cs(124,27): (Location of symbol related to previous error) TemplateCommand.cs(6,16): error CS0535: 'DotNetDataProviderTemplate.TemplateCommand' does not implement interface member 'System.IDisposable.Dispose'

-and-

TemplateTransaction.cs(6,16): error CS0535: 'DotNetDataProviderTemplate.TemplateTransaction' does not implement interface member 'System.Data.IDbTransaction.Connection'

TemplateTransaction.cs(6,16): error CS0535: 'DotNetDataProviderTemplate.TemplateTransaction' does not implement interface member 'System.IDisposable.Dispose'

-and-

TemplateDataReader.cs(7,16): error CS0535: 'DotNetDataProviderTemplate.TemplateDataReader' does not implement interface member 'System.IDisposable.Dispose'



MORE INFORMATION
To resolve these errors, you must modify the code in the Visual C# .NET samples.

TemplateCommand.cs
  Open TemplateCommand.cs. Replace the code in the CreateParameter method with the following code: public IDbDataParameter CreateParameter {     return (IDbDataParameter)(new TemplateParameter); }                     Add the following code to TemplateCommand.cs before the end of the class: void IDisposable.Dispose {     this.Dispose(true); System.GC.SuppressFinalize(this); }

private void Dispose(bool disposing) {     /*       * Dispose of the object, and perform any cleanup. */

}                    Save and close TemplateCommand.cs.

TemplateDataReader.cs
  Open TemplateDataReader.cs. Replace the code in the GetValues method with the following code: public int GetValues(object[] values) {     int i = 0, j = 0; for (i < values.Length && j < m_resultset.metaData.Length; i++, j++) {       values[i] = m_resultset.data[m_nPos, j]; }

return i;   }   Add the following code to TemplateDataReader.cs before the end of the class: void IDisposable.Dispose {     this.Dispose(true); System.GC.SuppressFinalize(this); }

private void Dispose(bool disposing) {     if (disposing) {       try {         this.Close; }       catch (Exception e)         { throw e;       } }   }                     Save and close TemplateDataReader.cs.</li></ol>

TemplateTransaction.cs
  Open TemplateTransaction.cs. Add the following code before the end of the class: public IDbConnection Connection {     /*       * Return the connection for the current transaction. */

get { return this.Connection; } }

public void Dispose {     this.Dispose(true); System.GC.SuppressFinalize(this); }

private void Dispose(bool disposing) {     if (disposing) {       if (null != this.Connection) {         // Implicitly roll back if the transaction still valid. this.Rollback; }                     }    }                    </li> Save and close TemplateTransaction.cs.</li></ol>

TemplateConnection.cs
  Open TemplateConnection.cs. Add the following code before the end of the class: void IDisposable.Dispose {     this.Dispose(true); System.GC.SuppressFinalize(this); }

private void Dispose(bool disposing) {     /*       * Dispose of the object, and perform any cleanup. */

if (m_state == ConnectionState.Open) this.Close; }                   </li> Save and close TemplateConnection.cs.</li> Compile and run the sample.</li></ol>

Additional query words: Implementing a .NET Data Provider TemplateCommand TemplateDataReader TemplateTransaction TemplateConnection

Keywords: kbprb kbdocerr KB317952

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.