OleDbException.没有为一个或多个必需参数提供值 [英] OleDbException. No value given for one or more required parameters

查看:91
本文介绍了OleDbException.没有为一个或多个必需参数提供值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\a.xlsx" + ";Extended Properties='Excel 12.0 Xml;HDR=No'";
        OleDbConnection conn = new OleDbConnection(connString);
        OleDbCommand cmd = new OleDbCommand("Update [tablenameeee$] SET A1='15'", conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();

我想访问excel中的特定单元格并更改其值.但我有例外

i want to access a specific cell in excel , and change its value . but i got the exception

OleDbException.没有为一个或多个必需参数给出值.解决方案是什么?

OleDbException. No value given for one or more required parameters.What is the solution ?

推荐答案

如果使用HDR = NO,则列名称为F1,F2,F3等……

If you use HDR=NO the column names are F1, F2 F3 etc......

OleDbCommand cmd = new OleDbCommand("Update [tablenameeee$] SET F1='15'", conn); 

但是我认为您应该指定WHERE子句来分隔受影响的行.
请记住,使用OleDb时,您不应该考虑行/列,而要考虑记录.

but I think you should specify a WHERE clause to delimit the affected rows.
Remeber, using OleDb you should not think in terms of Rows/Columns but in terms of Records.

或者,如果您确切知道要更新的行/列,则可以使用

As an alternative, if you know exactly the row/column to update you could use

OleDbCommand cmd = new OleDbCommand("Update [tablenameeee$A1:A1] SET F1='15'", conn); 

这篇关于OleDbException.没有为一个或多个必需参数提供值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆