简体   繁体   中英

Connect web form to external Access database

I'm trying to figure out how to connect a website form to an external Microsoft Access database. The website and database are on different servers. The website is going through a hosting company and the database is located inside a company office network.

My goal is to have users fill out an online form and then that information will be sent and saved to the Access database.

Is there a tutorial on this or does anyone have any suggestions?

TODO: You'll need to change the path to the mdb (in the connection string), probably hook up to some button click event instead of form load, change the table name (tblYourData) and the field names (field1, field2, etc) in the sql string, and instead of using 'some text', use the .Text property of the textbox on the page.

protected void Form_Load()
{
    string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;";
    string sql = "insert into tblYourData (field1, field2) values ('some text', 'some more text')";
    CreateCommand(sql, connstring);
}
private static void CreateCommand(string queryString, string connectionString)
{
    using (OleDbConnection connection = new OleDbConnection(
               connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        command.Connection.Open();
        command.ExecuteNonQuery();
    }
}

--Edit #1 --

This can only be done with the MDB is located on the same network (local hard drive, or network file share) as the IIS server.

Considering this isn't possible, you have a couple of options.

Option 1:

  1. Save it to a local database (sql express, sql server, etc...)
  2. Allow them to set up a linked server between the access database and your database.

Option 2:

  1. Save it to a local database (sql express, sql server, etc...)
  2. Allow them to export the data to a CSV or similar format.
  3. Then they can import that data into their Access database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM