Article ID: 317952 - Last Review: March 7, 2002 - Revision: 1.2

DOC: Corrections to Visual C# .NET Samples in "Sample .NET Data Provider" Documentation

This article was previously published under Q317952
Expand all | Collapse all

SUMMARY

When you try to compile the Visual C# .NET sample code that is included in the Sample .NET Data Provider (http://msdn.microsoft.com/en-us/library/26xsd945.aspx) 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

  1. Open TemplateCommand.cs. Replace the code in the CreateParameter method with the following code:
        public IDbDataParameter CreateParameter()
        {
          return (IDbDataParameter)(new TemplateParameter());
        }
    					
  2. 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.
           */ 
    
        }
    					
  3. Save and close TemplateCommand.cs.

TemplateDataReader.cs

  1. 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;
        }
    					
  2. 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;
            }
          }
        }
    					
  3. Save and close TemplateDataReader.cs.

TemplateTransaction.cs

  1. 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();
            }                
          }
        }
    					
  2. Save and close TemplateTransaction.cs.

TemplateConnection.cs

  1. 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();
        }
    					
  2. Save and close TemplateConnection.cs.
  3. Compile and run the sample.

APPLIES TO
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual C# .NET 2002 Standard Edition
Keywords: 
kbdocerr kbprb KB317952
 

Article Translations