VotingDemoDataContext db = new VotingDemoDataContext();
var x = (from name in db.Elections select name);
int n = x.Count();
Election election = new Election();
election.ElectionID = n.ToString();
Constituency c=new Constituency();
election.ConstituencyId = Convert.ToInt32(from m in db.Elections where (c.ConstituencyName==ddlConstitency.SelectedItem.Text) select m.ConstituencyId);
election.Date = Convert.ToDateTime(txtDate.Text);
election.ElectionType = ddlEType.SelectedItem.Text;
election.EO = txtEOName.Text;
election.EOPassword = txtEOPassword.Text;
db.Elections.InsertOnSubmit(election);
db.SubmitChanges();
txtEOPassword.Text = "";
txtDate.Text = "";
txtResultDate.Text = "";
ddlConstitency.SelectedIndex = 0;
ddlEType.SelectedIndex = 0;
txtEOName.Text = "";
This code is returning null exception for the line: election.ConstituencyId = Convert.ToInt32(from m in db.Elections where (c.ConstituencyName==ddlConstitency.SelectedItem.Text) select m.ConstituencyId);