- 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);
}
}
}
}