如何使用 OleDbDataAdapter Fill 方法仅添加确定数量的行?

发布于 2024-12-14 14:41:41 字数 714 浏览 2 评论 0原文

我想在数据集中添加行,但仅限特定数量的行(以避免“定义的字段过多”异常)。这是我到目前为止所尝试过的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2024-12-21 14:41:41

您可以指定希望 Fill() 方法检索的行数。以下是来自 MSDN 的签名:

public int Fill(
    int startRecord,
    int maxRecords,
    params DataTable[] dataTables
)

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:

public int Fill(
    int startRecord,
    int maxRecords,
    params DataTable[] dataTables
)

http://msdn.microsoft.com/en-us/library/0z5wy74x.aspx

仄言 2024-12-21 14:41:41

嗯,我相信你不能通过限制来解决字段太多的问题。

但限制字段是可以的。您第一次尝试的问题

TOP 100 FROM 

是语法无效。如果你想限制字段,你需要显式地使用像这样的列名。

SELECT TOP 100 ColumnName1, ColumnName2, ColumnName3 from ....

一般来说,我建议永远不要使用 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

TOP 100 FROM 

is that the syntax is not valid. If you want to limit the fields, you need to explicitly use the columnnames like this

SELECT TOP 100 ColumnName1, ColumnName2, ColumnName3 from ....

In general, I would recommend never to use select * but always precisely the columns you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文