I have this code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Access_Database
{
    public partial class Form1 : Form
    {
        private OleDbConnection myconnection;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string strconn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\dell\Desktop\Database\Student_Access.mdb;Persist Security Info=False";
            myconnection = new OleDbConnection(strconn);
            myconnection.Open();


            string query = "insert into tblStudent values('" + textBox1.Text + "','"+textBox2.Text+"','"+textBox3.Text+"');";
            OleDbCommand mycommand = new OleDbCommand(query, myconnection);
            mycommand.ExecuteNonQuery();
            MessageBox.Show("successfull");




        }
    }
}

but the error is "could not find file"

what should i do?
reagards..

Recommended Answers

All 2 Replies

I'm not that familiar with C# but try replacing

Source=C:\Users\dell\Desktop\Database\Student_Access.mdb

with

Source=C:\\Users\\dell\\Desktop\\Database\\Student_Access.mdb

I'm not that familiar with C# but try replacing

The 'at' symbol in front of the initial double quote makes it a verbatim string literal; no escaping is necessary for the backslashes.

but the error is "could not find file"

I presume the exception is thrown in the call to myconnection.Open()--is that correct? Could you include the entire exception message?

Also, I have to ask... the file does exist, right? Can you copy that file path into Explorer and get Access to open the file?

If the file exists, then this might be a security/permissions-related issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.