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!");
2
  • 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? Commented Dec 16, 2014 at 7:07
  • @Ragavi Try this : stackoverflow.com/questions/10447015/… Commented Dec 16, 2014 at 7:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.