Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Last active December 27, 2015 16:39
Show Gist options
  • Save hagbarddenstore/7356730 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/7356730 to your computer and use it in GitHub Desktop.
private IEnumerable<DataRow> RetrieveVendor(string table, string system, string region, params string[] fields)
{
var table = new DataTable();
var databaseFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "inu.db3");
if (!System.IO.File.Exists(databaseFile))
{
MessageBox.Show(string.Format("I couldn't find the file `{0}'!", databaseFile));
}
var connectionString = string.Format("Data Source={0}", databaseFile);
try
{
using (var connection = new SQLiteConnection(connectionString))
{
var query = string.Format("SELECT {0}, vpn FROM {1} WHERE system = ? AND region = ?", string.Join(", ", fields), table);
using (var command = connection.CreateCommand(query))
using (var adapter = new SQLiteDataAdapter(command))
{
command.Parameters.AddWithValue("@system", system);
command.Parameters.AddWithValue("@region", region);
connection.Open();
adapter.Fill(table);
connection.Close();
}
}
}
catch (SQLiteException exception)
{
MessageBox.Show(exception.ToString());
}
return table.Rows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment