public List <Municipality> selectMunicipalities() { List <Municipality> result = new List <Municipality>(); try { openConnection(); string sql = "select * from municipalities"; SqlCommand command = new SqlCommand(sql, conn); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Municipality mun = new Municipality(); mun.OB_ID = Int32.Parse(reader.GetValue(0) + ""); mun.OB_NAME = reader.GetValue(1) + ""; mun.OB_UNAME = reader.GetValue(2) + ""; result.Add(mun); } closeConnection(); } catch (Exception e) { Console.WriteLine("Error: " + e); } return(result); }
protected void btnInput_Click(object sender, EventArgs e) { municipalitiesEntities db = new municipalitiesEntities(); ObservableCollection <Municipality> munN = new ObservableCollection <Municipality>(db.Municipalities.Where(a => a.Name == txtNameMunicipalities.Text)); //ne postoi opstina so toa ime if (munN.Count == 0) { Municipality m = new Municipality(); m.Name = txtNameMunicipalities.Text; m.FBId = txtFBLink.Text; m.TwitterID = txtTwitterLink.Text; m.YTId = txtYTLink.Text; db.Municipalities.Add(m); db.SaveChanges(); } else { lblExist.Visible = true; } }