在c#中的Excel工作表上编写查询

时间:2010-02-18 04:49:36

标签: excel

我想从我的asp.net应用程序更新excel表的特定行。我能读取excel,但是如何更新记录。我可以写更新查询。怎么样 。请发给我代码:

        string strQuery = "UPDATE [Sheet1$]  SET Child Name=" + "\"" + strDataToUpdate[0] + "\",";
        strQuery = strQuery + "Pickup Point Name=" + "\"" + strDataToUpdate[1] + "\",";
        strQuery = strQuery + "Pickup Bus No=" + "\"" + strDataToUpdate[2] + "\",";
        strQuery = strQuery + "Pickup Bus Time=" + "\"" + strDataToUpdate[3] + "\",";
        strQuery = strQuery + "Drop Down Point Name=" + "\"" + strDataToUpdate[4] + "\",";
        strQuery = strQuery + "Drop Bus No=" + "\"" + strDataToUpdate[5] + "\",";
        strQuery = strQuery + "Drop Down Bus Time=" + "\"" + strDataToUpdate[6] + "\",";
        strQuery = strQuery + "Parent Name=" + "\"" + strDataToUpdate[7] + "\",";
        strQuery = strQuery + "Mobile 1=" + "\"" + strDataToUpdate[8] + "\",";
        strQuery = strQuery + "Mobile 2=" + "\"" + strDataToUpdate[9] + "\",";
        strQuery = strQuery + "Email ID 1=" + "\"" + strDataToUpdate[10] + "\",";
        strQuery = strQuery + "Email ID 2=" + "\"" + strDataToUpdate[11] + "\",";
        strQuery = strQuery + "Service Mode=" + "\"" + strDataToUpdate[12] + "\",";
        strQuery = strQuery + "WHERE Child Id=" + strDataToUpdate[13];

此查询我正在使用给出语法错误。请指导

3 个答案:

答案 0 :(得分:2)

您可以通过 ADO.NET 使用它。这解释为here

答案 1 :(得分:0)

SpreadsheetGear for .NET可以做到。

如果您想亲自尝试,可以使用C#和VB源代码here查看实时ASP.NET示例并下载免费试用版here

免责声明:我拥有SpreadsheetGear LLC

答案 2 :(得分:0)

当您的字段名称包含空格时,您必须将字段名称放在括号中,例如:

string strQuery = "UPDATE [Sheet1$]  SET [Child Name]=" + "\"" + strDataToUpdate[0] + "\",";