Hello,
I am using visual studio2012 for designing a windows application with ms-access 2007 database . I tried to connect the database but i got the error
An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.
Please help me
Here is my Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace Nilkamal
{
public partial class addnewspaper : Form
{
public addnewspaper()
{
InitializeComponent();
}
private OleDbConnection conn2 = new OleDbConnection();
private void Form2_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
conn2.ConnectionString = "@Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\DEVENDRA\\Documents\\nilkamal.mdb";
string newspaper_name = txtPaper.Text;
conn2.Open();
OleDbCommand cmd = new OleDbCommand("insert into newspaper_detail(newspaper_name)" + "values(@newspaper_name)", conn2);
if (conn2.State == ConnectionState.Open)
{
cmd.Parameters.Add("@newspaper_name", OleDbType.Char, 50);
cmd.Parameters["@newaper_name"].Value = newspaper_name;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Records Inserted");
conn2.Close();
}
catch(OleDbException exp)
{
MessageBox.Show(exp.Source);
}
}
else
{
MessageBox.Show("Connection failed");
}
}
}
}