Im doing a project and I want to add a record to an accdb(Access databse) using a windows forms application on C# I have got what appears to be code that works i.e. it doesnt show any errors and appears to run however it doesnt add the record, how can I be sure that add this record (image)? Any ideas, code, help would be much appreciated
this is my code
enter code here
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Abrir escudo de municipio";
//openFileDialog1.Filter ="IMG Files|*.jpg|JPG Files|*.png|PNG Files|*.bmp Files|BMP Files|";
openFileDialog1.Filter = "JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp";
openFileDialog1.InitialDirectory = @"C:\";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// textBox1.Show(openFileDialog1.FileName.ToString());
//MessageBox.Show(openFileDialog1.FileName.ToString());
textBox1.Text = openFileDialog1.FileName.ToString();
String filename = openFileDialog1.FileName.ToString();
byte[] buffer = File.ReadAllBytes(filename);
using (var conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Policias.accdb"))
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "INSERT INTO DetallesMunicipio(imagen) VALUES (@imagen)";
cmd.Parameters.AddWithValue("@imagen", buffer);
conn.Open();
cmd.ExecuteNonQuery();
}
}
else
{
MessageBox.Show("Please select an image");
}
}