0

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..

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by gusano79
0

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
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.