Skip to main content
added 131 characters in body
Source Link
SiD
  • 597
  • 2
  • 8
  • Use namespace CompanyXCompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapterInvoiceTableAdapter and SqlConnectionSqlConnection and reuse it.
  • In UpdateInvoiceUpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1'Update1 method.
  • You will need to put the cleanup of the connection in a Dispose()Dispose() after making the data access class IDisposableIDisposable. As pointed out by ratchet freak in another answer.
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
  • You will need to put the cleanup of the connection in a Dispose() after making the data access class IDisposable.
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside Update1 method.
  • You will need to put the cleanup of the connection in a Dispose() after making the data access class IDisposable. As pointed out by ratchet freak in another answer.
added 52 characters in body
Source Link
SiD
  • 597
  • 2
  • 8
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
  • You will need to put the cleanup of the connection in a Dispose() after making the data access class IDisposable.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess : IDisposable
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                using (ta.Connection = readerConnection)
                {readerConnection;
                    return ta.GetByID(ID);
                }
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                using (ta.Connection = readerConnection)
                {readerConnection;
                    return ta.Get(userSID);
                }
            }

            public void DeleteInvoice(int ID)
            {
                using (ta.Connection = writerConnection)writerConnection;
                {ta.Delete1(ID);
            }

        ta.Delete1    public void UpdateInvoice(IDInvoice m);
            {
    }
            }

ta.Connection = writerConnection          public void UpdateInvoice(Invoice m)
            {
            
     using (ta.Connection = writerConnection        ta.Update1(m);
            }

    {  
       public void Dispose()
            ta.Update1(m);{
                }// Do clean up
            }
        }
    }
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.GetByID(ID);
                }
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.Get(userSID);
                }
            }

            public void DeleteInvoice(int ID)
            {
                using (ta.Connection = writerConnection)
                {
                    ta.Delete1(ID);
                }
            }

            public void UpdateInvoice(Invoice m)
            {
                using (ta.Connection = writerConnection)
                {  
                     ta.Update1(m);
                }
            }
        }
    }
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
  • You will need to put the cleanup of the connection in a Dispose() after making the data access class IDisposable.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess : IDisposable
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                ta.Connection = readerConnection;
                return ta.GetByID(ID);
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                ta.Connection = readerConnection;
                return ta.Get(userSID);
            }

            public void DeleteInvoice(int ID)
            {
                ta.Connection = writerConnection;
                ta.Delete1(ID);
            }

            public void UpdateInvoice(Invoice m)
            {
                ta.Connection = writerConnection                                     
                ta.Update1(m);
            }

            public void Dispose()
            {
                // Do clean up
            }
        }
    }
added 99 characters in body
Source Link
SiD
  • 597
  • 2
  • 8
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.GetByID(ID);
                }
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.Get(userSID);
                }
            }

            public void DeleteInvoice(int ID)
            {
                using (ta.Connection = writerConnection)
                {
                    ta.Delete1(ID);
                }
            }

            public void UpdateInvoice(Invoice m)
            {
                using (ta.Connection = writerConnection)
                {  
                    ta.Update1(m.ID, ... n numbers of params ..., m.ModifiedBy);
                }
            }
        }
    }
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.GetByID(ID);
                }
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.Get(userSID);
                }
            }

            public void DeleteInvoice(int ID)
            {
                using (ta.Connection = writerConnection)
                {
                    ta.Delete1(ID);
                }
            }

            public void UpdateInvoice(Invoice m)
            {
                using (ta.Connection = writerConnection)
                {  
                    ta.Update1(m.ID, ... n numbers of params ..., m.ModifiedBy);
                }
            }
        }
    }
  • Use namespace CompanyX instead of using in every method's return type.
  • Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
  • In UpdateInvoice method, instead of passing multiple properties, pass data model itself and use properties which are required inside 'Update1' method.
    using CompanyX;
    using CompanyX.DataAccess.CompanyXTableAdapters;

    namespace CompanyX.DataAccess
    {
        public class CompanyXDataAccess
        {
            InvoiceTableAdapter ta = new InvoiceTableAdapter();
            SqlConnection readerConnection = new SqlConnection(DB.GetReaderConnectionString());
            SqlConnection writerConnection = new SqlConnection(DB.GetWriterConnectionString());
        
            public InvoiceDataTable GetInvoiceByID(int ID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.GetByID(ID);
                }
            }

            public InvoiceDataTable GetInvoice(string userSID)
            {
                using (ta.Connection = readerConnection)
                {
                    return ta.Get(userSID);
                }
            }

            public void DeleteInvoice(int ID)
            {
                using (ta.Connection = writerConnection)
                {
                    ta.Delete1(ID);
                }
            }

            public void UpdateInvoice(Invoice m)
            {
                using (ta.Connection = writerConnection)
                {  
                    ta.Update1(m);
                }
            }
        }
    }
Source Link
SiD
  • 597
  • 2
  • 8
Loading