I am trying to access an SQLite 3 database programmatically using the code below:
private void button1_Click(object sender, EventArgs e)
{
try
{
string connectionPath = @"Data Source=C:\temp\sms.db";
SQLiteConnection connection = new SQLiteConnection(connectionPath);
SQLiteCommand command = connection.CreateCommand();
connection.Open();
string query = "SELECT * FROM Message";
command.CommandText = query;
command.ExecuteNonQuery();
SQLiteDataAdapter dataAdaptor = new SQLiteDataAdapter(command);
DataSet dataset = new DataSet();
dataAdaptor.Fill(dataset, "messages");
dataGridView1.DataSource = dataset.Tables["messages"];
connection.Close();
}
catch
{
MessageBox.Show("error", "error", MessageBoxButtons.OK);
}
}
However whenever I press the button this code is assigned to, it doesn't catch on the Try Catch and display my message box, it freezes for a few seconds and debugs into the Program.cs file at the line shown below
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMainWindow()); **<----This Line**
}
}
At that line it then displays this error to me
Could not load file or assembly 'System.Data.SQLite, Version=1.0.76.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies.
An attempt was made to load a program with an incorrect format.
How can I overcome this error so I can query the database?
EDIT
My development OS is Win 7 x64 Prof
I have installed:
Setups for 64-bit Windows (.NET Framework 4.0)
Setups for 32-bit Windows (.NET Framework 4.0)
from heresystem.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki