Skip to content

Instantly share code, notes, and snippets.

@gsedubun
Created August 6, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsedubun/8147c9d1a599f04d2e6e1bf469f33582 to your computer and use it in GitHub Desktop.
Save gsedubun/8147c9d1a599f04d2e6e1bf469f33582 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Data.SqlClient;
using Dapper;
namespace tracking.Models
{
public class AirportRepository{
// change the user id and password accordingly.
private const string connstring = "Data Source=.\\sqlexpress;Initial Catalog=OSM_DB;user id=[id]; password=[password]";
private SqlConnection Connection;
public AirportRepository()
{
this.Connection = new SqlConnection(connstring);
}
public IEnumerable<Airport> Search(string name){
name = "%"+name+"%";
var data = Connection.Query<Airport>(@"select top 100 Name,Code,Latitude,Longitude,City,Country from airports
where name like @name", new {name});
if(data!=null)
{
return data;
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment