如何准备包含 NText (clob) 参数的 ADO.NET 语句

发布于 2024-10-03 06:04:38 字数 604 浏览 0 评论 0原文

我正在更新一个现有的应用程序,该应用程序使用工厂来构建准备好的语句,然后稍后执行它们,这适用于系统的其余部分,但我的任务是添加对使用 的语句的调用NText,我不知道如何正确准备该声明。我收到以下运行时错误:

SqlCommand.Prepare 方法要求所有可变长度参数都具有显式设置的非零大小。

但我不确定 Length 使用什么值?

代码示例:

SqlCommand update = new SqlCommand("UPDATE Log.Response_File_Log " +
  "SET File = @File " +
  ", DateFileReceived = GETDATE() " +
  "WHERE RunID = @RunID", _connection);
update.Parameters.Add(new SqlParameter("@File", SqlDbType.NText));
update.Parameters.Add(new SqlParameter("@RunID", SqlDbType.Int));
update.Prepare();

I'm updating an existing application which uses a factory to build prepared statements, and then execute them later, which works for the rest of the system, but I've been tasked with adding a call to a statement which uses an NText, and I cannot figure out how to properly prepare the statement. I am getting a runtime error of:

SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.

but I'm not sure what value to use for the Length?

Code sample:

SqlCommand update = new SqlCommand("UPDATE Log.Response_File_Log " +
  "SET File = @File " +
  ", DateFileReceived = GETDATE() " +
  "WHERE RunID = @RunID", _connection);
update.Parameters.Add(new SqlParameter("@File", SqlDbType.NText));
update.Parameters.Add(new SqlParameter("@RunID", SqlDbType.Int));
update.Prepare();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

耳根太软 2024-10-10 06:04:38

Don't use NTEXT, is a deprecated type. If your database has an NTEXT column change it to VARBINARY(MAX). Use -1 for MAX type parameters length: (...,SqlDbType.Varbinary, -1).

Spring初心 2024-10-10 06:04:38

您可以将其设置为传递给 @File 参数的数据的长度吗?这只是一个建议。

Can you set it to the length of the data you're passing in to @File parameter? This is just a suggestion.

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