Skip to content

Instantly share code, notes, and snippets.

@fugaku
Created November 29, 2018 15:11
Show Gist options
  • Select an option

  • Save fugaku/83702c881808f9b7cf5234c1c8fea8e0 to your computer and use it in GitHub Desktop.

Select an option

Save fugaku/83702c881808f9b7cf5234c1c8fea8e0 to your computer and use it in GitHub Desktop.
ODBC Connection
public class OdbcRepository
{
public List<Model> Get(string name)
{
//Create a connection
var connection = new OdbcConnection(connectionString);
//Construct the query
//Usually you use @parameter as the syntax for querying SQL Server
//But for querying to Microsoft Access you must use ?
var queryText = "SELECT * FROM table1 WHERE Name = ?";
//Use dapper to query with parameter
//It's also a good idea if you use a string as a parameter that you use DbString instead of sending the variable directly
//You will also need to specify the Length exactly as the length of the column in the Microsoft Access table
var data = connection.Query<Model>(queryText, new { Name = new DbString { Value = name, Length = 10, IsAnsi = true } });
return data.ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment