Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");
}
}

}
}
Posted
Comments
Thanks7872 21-Oct-13 3:04am    
Copy error text,paste it in google and see what happens.
Devendra Dighe 21-Oct-13 3:16am    
got the answer

1 solution

http://msdn.microsoft.com/en-us/library/ms171893.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900