0

here my code which need to save data from excel sheet to database access using C#. I don't get any error but my excel data could not be updated in database access.. What I have to do for this?

My Database Access Tablename is "addsales1".

My Excel sheet name is "addsales1".

string file_name = Application.StartupPath + "\\" + "databaseset.txt";
System.IO.StreamReader objreader;
objreader = new System.IO.StreamReader(file_name);
string sh = objreader.ReadLine();
string con = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox9.Text 
    + ";Extended Properties=Excel 8.0;";

OleDbConnection connection = new OleDbConnection(con);
OleDbCommand cmd = new OleDbCommand("INSERT INTO [MS Access;Database=" + sh + 
    "].[addsales1] SELECT * FROM [addsales1$]");

cmd.Connection = connection;
connection.Open();

cmd.ExecuteNonQuery();
connection.Close();

MessageBox.Show("Sales Details Imported Successfully!");
Katie Kilian
  • 6,815
  • 5
  • 41
  • 64
Ragavi
  • 19
  • 3
  • That SQL statement you're using to insert and select ... I'm not sure what that is. It looks wrong. You really get no errors at all? What happens when you set a breakpoint and step over the code? – Katie Kilian Dec 16 '14 at 07:07
  • @Ragavi Try this : http://stackoverflow.com/questions/10447015/uploading-an-excel-sheet-and-importing-the-data-into-sql-server-database – Thirisangu Ramanathan Dec 16 '14 at 07:13

0 Answers0