I have a problem with my C# project application when I try to insert my textbox values into Microsoft Excel.
When I input 00001234
in my text box, it only writes 1234
in my Excel file.
This is my code:
System.Data.OleDb.OleDbConnection myConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
string path = "'E:\\test.xls'";
string A = "AS";
myConnection = new System.Data.OleDb.OleDbConnection("provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";Extended Properties= Excel 4.0");
myConnection.Open();
myCommand.Connection = myConnection;
sql = "Insert into [Sheet1$]" + "([ID],[Name])" + "values (" + textBox1.Text + "," + textBox2.Text + ")";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
myConnection.Close();