hi, i need to create database in the folder which the user selects
the code below creates database in folder D:\\AccessDb

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
                   "Data Source=D:\\AccessDB\\shell.mdb;" +
                   "Jet OLEDB:Engine Type=5");

I have used the folderdialog, and store the location of which the user selects into a string and replace the D:\\AccessDb with the string value, but it give me a error
the dbLocation is the string which holds the folder the user selected
such as D:\data, it does not work, it gives me error

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
       "Data Source='" + dbLocation + "'\\shell.mdb;" +
       "Jet OLEDB:Engine Type=5");

Hi, I didnt get you well.
You need to create a NEW folder some where on hdd to store your dataBase inside of it, Am I right?

Hi, I didnt get you well.
You need to create a NEW folder some where on hdd to store your dataBase inside of it, Am I right?

hi, somehow , but the new folder will be selected by the user.
A folder select dialog will open, user selects the folder
now the folder the user selected is stored into a string variable
and i want to create the database in the folder which the user selected
dbLocation is the string variable which the data in it is: D:\
it gives me error "format of string does not confirm to oleb"

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
       "Data Source='" + dbLocation + "'\\shell.mdb;" +
       "Jet OLEDB:Engine Type=5");

but without passing parameter like this
it would work fine:

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
       "Data Source=D:\\AccessDB\\shell.mdb;" +
       "Jet OLEDB:Engine Type=5");

Try to use FolderBrowerDialog, to create or select directory:

public partial class Form1 : Form
    {
        string connString;
        string dirPath;
        public Form1()
        {
            InitializeComponent();            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog openFileDialog1 = new FolderBrowserDialog();
            // Show the FolderBrowserDialog.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                dirPath = openFileDialog1.SelectedPath;
                connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dirPath + "\\shell.mdb;Jet OLEDB:Engine Type=5";
                MessageBox.Show("This is the full connection string:\n" + connString);
            }
        }
    }

If I got your right, this is than it. Tell me what do you think.

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.