public List <tour> getAllPlace() { List <tour> users = new List <tour>(); tour u; SqlConnection con = null; SqlCommand cmd = null; try { con = new SqlConnection(); con.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Database;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; using (con) { string command = "select * from Place"; cmd = new SqlCommand(command, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { u = new tour(); u.placeid = (int)rdr["placeid"]; u.name = rdr["name"].ToString(); u.desc = rdr["description"].ToString(); u.price = rdr["price"].ToString(); u.imagepath = rdr["imagepath"].ToString(); users.Add(u); } rdr.Close(); System.Console.WriteLine(users); return(users); } } catch (Exception err) { return(users); } finally { if (con != null) { con.Dispose(); } if (cmd != null) { cmd.Dispose(); } } }
void getPlace1() { List <tour> users = new List <tour>(); tour u; SqlConnection con = null; SqlCommand cmd = null; try { con = new SqlConnection(); con.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Database;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; using (con) { //Label1.Text += fplaces.Count; for (int i = 0; i < fplaces.Count; i++) { string command = "select * from Place where placeid= '" + fplaces[i] + "'"; cmd = new SqlCommand(command, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { u = new tour(); //Label2.Text += rdr["placeid"]; u.placeid = (int)rdr["placeid"]; u.name = rdr["name"].ToString(); u.desc = rdr["description"].ToString(); u.price = rdr["price"].ToString(); u.imagepath = rdr["imagepath"].ToString(); places.Add(u); } con.Close(); System.Console.WriteLine(users); } } } catch (Exception err) { } finally { con.Close(); } }