Up till now most of the web apps Ive built have an Oracle database behind them, so when fetching or updating data, Id pass search variables to a class to build the SQL, open a connection and create a DataTable to pass back to the form which I then bind to a gridview - easy stuff.
I'm now using Linq for a SQL Server database. I can easily build this up and get it working on a button_click event (code below), but if I were to pass the variables to a separate class to do this so that it not running from code-behind, what exactly is it Im returning back to the form?
Hope that makes sense - I'm basically wanting to do whats below but not in code-behind.
ASB_DataDataContext adb = new ASB_DataDataContext();
var qryAdb = from asb in adb.Inputts
select new
{
NRTno = asb.NRT_No,
PerpSurname = asb.Allg_Perp_Surname,
PerpSteet = asb.Allg_Perp_Street,
HouseNo = asb.Allg_Perp_House_No,
Complainer = asb.Complainant_Surname,
Complainer_Street = asb.Complainant_Street
};
if (txtCompSurname.Text != "")
qryAdb = qryAdb.Where(asb => asb.Complainer == txtCompSurname.Text);
if (txtCompStreet.Text != "")
qryAdb = qryAdb.Where(asb => asb.Complainer_Street == txtCompStreet.Text);
if (txtPerpSurname.Text != "")
qryAdb = qryAdb.Where(asb => asb.PerpSurname == txtPerpSurname.Text);
if (txtPerpStreet.Text != "")
qryAdb = qryAdb.Where(asb => asb.PerpSteet == txtPerpStreet.Text);
if (txtNrtNo.Text != "")
qryAdb = qryAdb.Where(asb => asb.NRTno == Convert.ToInt32(txtNrtNo.Text));
gvResults.DataSource = qryAdb.Select(o => new { o.NRTno, o.PerpSurname, o.PerpSteet, o.HouseNo, o.Complainer, o.Complainer_Street });
gvResults.DataBind();
SqlCommandand useDataTableobjects to bind to gridviews etc.