Readability
- Use namespace CompanyX instead of using in every method's return type.
- Create single instance of InvoiceTableAdapter and SqlConnection and reuse it.
Not sure why you're using 2 SQL connections. I would suggest you to use only one.
After refactoring code should look like this:
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);
}
}
}
}