在C#中的OleDbConnection

我已经编写了将数据插入到Excel表单中的代码。我的代码不会抛出任何exception,并且每次Excel文件的大小都会增加1KB。 但是当我打开表单时,它不显示任何数据。

我感到困惑,无法弄清楚这个问题。 请提前帮助和thanx … !!!

string strSQL = string.Empty; excelConn.Open(); strSQL = "INSERT INTO [" + sheetName + "$] ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11]) VALUES(@value1, @value2, @value3, @value4, @value5,@value6, @value7, @value8, @value9 ,@value10, @value11)"; excelCommand = new OleDbCommand(strSQL, excelConn); excelCommand.Parameters.AddWithValue("@value1", Program); excelCommand.Parameters.AddWithValue("@value2", District); excelCommand.Parameters.AddWithValue("@value3", Period); excelCommand.Parameters.AddWithValue("@value4", paramValue1); excelCommand.Parameters.AddWithValue("@value5", paramValue2); excelCommand.Parameters.AddWithValue("@value6", paramValue3); excelCommand.Parameters.AddWithValue("@value7", BusinessLogic); excelCommand.Parameters.AddWithValue("@value8", ExpectedResult); excelCommand.Parameters.AddWithValue("@value9", ActualResult); excelCommand.Parameters.AddWithValue("@value10", Status); excelCommand.Parameters.AddWithValue("@value11", DateTime); excelCommand.ExecuteNonQuery(); return true; 

OLEDB要求不应该命名参数。 您应该在查询中使用问号:

 strSQL = "INSERT INTO [" + sheetName + "$] ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";