Today is the first time I've used Linq, so I wanted to get a code review on this and make sure I'm going about it correctly.
I'm filling text boxes and dropdown lists from a table row.
protected void Page_Load(object sender, EventArgs e)
{
using (DBContext da = new DBContext())
{
string dob;
var detail = from a in da.tblPatients
where a.ID == 1198
select a;
foreach (var d in detail)
{
txtFirstName.Text = d.FirstName;
txtLastName.Text = d.LastName;
txtPreferredName.Text = d.PreferredName;
dob = d.DOB;
if(!String.IsNullOrEmpty(dob))
{
try
{
int lastindexofdob = 0;
string month = "";
string day = "";
string year = "";
lastindexofdob = dob.LastIndexOf("/");
month = dob.Substring(0, dob.IndexOf("/"));
day = dob.Substring(month.Length + 1, (dob.LastIndexOf("/") - month.Length) - 1);
year = dob.Substring(dob.Length - 4);
ddlDOBMonth.SelectedIndex = ddlDOBMonth.Items.IndexOf(ddlDOBMonth.Items.FindByValue(month));
ddlDOBDay.SelectedIndex = ddlDOBDay.Items.IndexOf(ddlDOBDay.Items.FindByText(day));
ddlDOBYear.SelectedIndex = ddlDOBYear.Items.IndexOf(ddlDOBYear.Items.FindByText(year));
}
catch { //error catching will go here}
}
txtAddress.Text = d.Address;
}
}
}
There are actually about 20 more input fields to do, but I wanted a code review at this point.