如何prepare ADO.NET的声明,其中包括一个NTEXT(CLOB)参数 [英] How to Prepare an ADO.NET Statement which includes an NText (clob) parameter

查看:260
本文介绍了如何prepare ADO.NET的声明,其中包括一个NTEXT(CLOB)参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新现有的应用程序,它使用一个工厂建prepared语句,然后再执行它们,其中工程系统的休息,但我一直在负责将调用一个声明它采用了ntext和我想不出如何正确prepare声明。我得到的运行时错误的SqlCommand。prepare方法要求所有可变长度的参数有一个明确设置非零的尺寸。但我不知道要使用的长度什么价值

强制性code样品:<​​/ P>

 的SqlCommand更新=新的SqlCommand(更新Log.Response_File_Log+
  集文件@file =+
  DateFileReceived = GETDATE()+
  WHE​​RE的runid = @runId,_connection);
update.Parameters.Add(新的SqlParameter(@文件,SqlDbType.NText));
update.Parameters.Add(新的SqlParameter(@的runid,SqlDbType.Int));
更新prepare()。
 

解决方案

不要使用 NTEXT ,是的德precated型。如果您的数据库有一个 NTEXT 列其更改为 VARBINARY(MAX)。使用-1 MAX 类型参数的长度:(...,SqlDbType.Varbinary,-1)

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

Obligatory 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();

解决方案

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).

这篇关于如何prepare ADO.NET的声明,其中包括一个NTEXT(CLOB)参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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