如何使用 OleDbDataAdapter Fill 方法仅添加确定数量的行?
我想在数据集中添加行,但仅限特定数量的行(以避免“定义的字段过多”异常)。这是我到目前为止所尝试过的:
OleDbCommand command = new OleDbCommand(@"SELECT TOP 100 FROM [" + SheetName + "]", connection);
异常:SELECT 语句包含拼写错误或丢失的保留字或参数名称,或者标点符号不正确。
OleDbCommand command = new OleDbCommand(@"SELECT * FROM [" + SheetName + "] LIMIT 100", connection);
异常:FROM 子句中存在语法错误。
我也尝试了从另一个 site
OleDbCommand command = new OleDbCommand(@"SELECT TOP 100 * FROM [" + SheetName + "]", connection);
异常:定义了太多字段。
我不知道还能尝试什么,有什么建议吗?
I want to add rows in a DataSet, but only a specific number of rows (in order to avoid the "Too many fields defined." exception). This is what I have tried so far:
OleDbCommand command = new OleDbCommand(@"SELECT TOP 100 FROM [" + SheetName + "]", connection);
Exception: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
OleDbCommand command = new OleDbCommand(@"SELECT * FROM [" + SheetName + "] LIMIT 100", connection);
Exception: Syntax error in FROM clause.
I also tried this that I got from another site
OleDbCommand command = new OleDbCommand(@"SELECT TOP 100 * FROM [" + SheetName + "]", connection);
Exception: Too many fields defined.
I have no idea what else to try, any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以指定希望
Fill()
方法检索的行数。以下是来自 MSDN 的签名:http://msdn.microsoft.com/en-us /library/0z5wy74x.aspx
You can specify how many rows you would like the
Fill()
method to retrieve. Here's its signature from MSDN:http://msdn.microsoft.com/en-us/library/0z5wy74x.aspx
嗯,我相信你不能通过限制行来解决字段太多的问题。
但限制字段是可以的。您第一次尝试的问题
是语法无效。如果你想限制字段,你需要显式地使用像这样的列名。
一般来说,我建议永远不要使用 select * ,但总是精确地使用你需要的列。
Well, I believe you cannot solve the problem that that are too many fields by limiting the rows.
But limiting the fields can be done. The problem with your first try
is that the syntax is not valid. If you want to limit the fields, you need to explicitly use the columnnames like this
In general, I would recommend never to use select * but always precisely the columns you need.