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



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft Visual C# .NET (2002)

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

  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.

Modification Type:MajorLast Reviewed:3/7/2002
Keywords:kbdocerr kbprb KB317952