I HAVE THIS ERRORS WHEN I TRY TO RUN MY CODE in visual studio 2012:
When i press save button:
-------------------------
1. An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
Additional information: ExecuteReader requires an open and available Connection. The connection's current state is closed.
When i press show all button:
--------------------------------
2. An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
Additional information: The 'Microsoft.ACE.OLEBD.12.0' provider is not registered on the local machine.
The code i run:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
OleDbConnection vcon=new OleDbConnection(@"Provider=Microsoft.ACE.OLEBD.12.0; Data source=C:\Users\user\Desktop\DBMS.accdb");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vcon.Open();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
string vsql = string.Format("insert into PartA values ((0),(1),(2),(3),(4))",textBox1.Text,int.Parse(textBox2.Text),textBox3.Text,textBox4.Text,textBox5.Text);
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
vcom.ExecuteReader();
MessageBox.Show("Data stored succesfully");
vcom.Dispose();
}
private void button4_Click(object sender, EventArgs e)
{
string vsql = "Select * from partA ";
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
DataSet vds = new DataSet();
OleDbDataAdapter vda = new OleDbDataAdapter(vcom);
vda.Fill(vds, "res");
dataGridView1.DataSource = vds.Tables["res"];
vda.Dispose();
vcom.Dispose();
}
What is the solution about this error??