private List <Representative> getRepRecords(string query) { List <Representative> repList = new List <Representative>(); //formulate connection string, sql query, data adapter/table //SqlConnection conn = new SqlConnection(@"Data Source=localhost\CGBPCD; Database=Assignment2; Integrated Security=True"); SqlConnection conn = new SqlConnection("Data Source=CGBPCD;Initial Catalog=Assignment2;Integrated Security=True"); SqlCommand cmd = new SqlCommand(query, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); //iterate through each record to create list of reps within passed in zipcode foreach (DataRow dr in dt.Rows) { //create our new rep object, and push into list Representative rep = new Representative(); //Set rep properties rep.Prefix = ""; //Do not have this data rep.FirstName = dr["person__firstname"].ToString(); rep.MiddleName = dr["person__middlename"].ToString(); rep.LastName = dr["person__lastname"].ToString(); rep.Suffix = dr["person__namemod"].ToString(); rep.Address = ""; //Do not have this data rep.City = ""; //Do not have this data rep.AddrState = ""; //Do not have this data rep.Zip4 = dr["ZCTA5CE10"].ToString(); //Do not have this data, using generic zip instead rep.StateDistrict = dr["state"].ToString() + dr["district"].ToString(); rep.BioguideID = dr["person__bioguideid"].ToString(); rep.Party = dr["party"].ToString(); rep.State = dr["state"].ToString(); rep.District = dr["district"].ToString(); repList.Add(rep); } return(repList); }
private List<Representative> getRepRecords(string query) { List<Representative> repList = new List<Representative>(); //formulate connection string, sql query, data adapter/table //SqlConnection conn = new SqlConnection(@"Data Source=localhost\CGBPCD; Database=Assignment2; Integrated Security=True"); SqlConnection conn = new SqlConnection("Data Source=CGBPCD;Initial Catalog=Assignment2;Integrated Security=True"); SqlCommand cmd = new SqlCommand(query, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); //iterate through each record to create list of reps within passed in zipcode foreach (DataRow dr in dt.Rows) { //create our new rep object, and push into list Representative rep = new Representative(); //Set rep properties rep.Prefix = ""; //Do not have this data rep.FirstName = dr["person__firstname"].ToString(); rep.MiddleName = dr["person__middlename"].ToString(); rep.LastName = dr["person__lastname"].ToString(); rep.Suffix = dr["person__namemod"].ToString(); rep.Address = ""; //Do not have this data rep.City = ""; //Do not have this data rep.AddrState = ""; //Do not have this data rep.Zip4 = dr["ZCTA5CE10"].ToString(); //Do not have this data, using generic zip instead rep.StateDistrict = dr["state"].ToString() + dr["district"].ToString(); rep.BioguideID = dr["person__bioguideid"].ToString(); rep.Party = dr["party"].ToString(); rep.State = dr["state"].ToString(); rep.District = dr["district"].ToString(); repList.Add(rep); } return repList; }