0

i want import Excel work sheet into ms acess existing table

      try
            {
                string conn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filename + ";" + "Extended Properties=Excel 12.0 Xml;";
                OleDbConnection con = new OleDbConnection(conn);
                OleDbCommand cmd = new OleDbCommand();
                con.Open();
                cmd.CommandText = @"SELECT * INTO [MS Access;Database=" + adb + "].[test] FROM [test$]";
                cmd.Connection = con;
                cmd.ExecuteNonQuery();
                MessageBox.Show("inserted");
                con.Close();
            }
            catch (DbException ex)
            {
                MessageBox.Show("Failed to access database");
                MessageBox.Show(ex.Message);
                return;
            }

but its create new table and insert values?
how i insert existitg existing databases ms access

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by Cameronsmith63
0

ok, im not sure what you want, but i'll try. Your question is, you want to insert data into an existing table?

Your SQL command "select into" creates a new table of data, that is not the command that you should be using.

You can write an "INSERT INTO (select * from....)

where your select statement in the brackets would be your subquery, the selection of what you want from the excel file, and inserted into an existing table.

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.