What size do you use for varchar(MAX) in your parameter declaration?

In this case you use -1.

See also MSDN docs: msdn.microsoft.com/en-us/library/bb399384.aspx

Using Large Value Type Parameters

Large value types can be used in SqlParameter objects the same way you use smaller value types in SqlParameter objects. You can retrieve large value types as SqlParameter values, as shown in the following example. The code assumes that the following GetDocumentSummary stored procedure exists in the AdventureWorks sample database. The stored procedure takes an input parameter named @DocumentID and returns the contents of the DocumentSummary column in the @DocumentSummary output parameter.

 
CREATE PROCEDURE GetDocumentSummary
(
@DocumentID int,
@DocumentSummary nvarchar(MAX) OUTPUT
)
AS
SET NOCOUNT ON
SELECT @DocumentSummary=Convert(nvarchar(MAX), DocumentSummary)
FROM Production.Document
WHERE DocumentID=@DocumentID

Example

The ADO.NET code creates SqlConnection and SqlCommand objects to execute the GetDocumentSummary stored procedure and retrieve the document summary, which is stored as a large value type. The code passes a value for the @DocumentID input parameter, and displays the results passed back in the @DocumentSummary output parameter in the Console window.

C#
static private string GetDocumentSummary(int documentID)
{
//Assumes GetConnectionString returns a valid connection string.
using (SqlConnection connection =
new SqlConnection(GetConnectionString()))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
try
{
// Setup the command to execute the stored procedure.
command.CommandText = "GetDocumentSummary";
command.CommandType = CommandType.StoredProcedure; // Set up the input parameter for the DocumentID.
SqlParameter paramID =
new SqlParameter("@DocumentID", SqlDbType.Int);
paramID.Value = documentID;
command.Parameters.Add(paramID); // Set up the output parameter to retrieve the summary.
SqlParameter paramSummary =
new SqlParameter("@DocumentSummary",
SqlDbType.NVarChar, -1);
paramSummary.Direction = ParameterDirection.Output;
command.Parameters.Add(paramSummary); // Execute the stored procedure.
command.ExecuteNonQuery();
Console.WriteLine((String)(paramSummary.Value));
return (String)(paramSummary.Value);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
}

What size do you use for varchar(MAX) in your parameter declaration?的更多相关文章

  1. SQL Server中Text和varchar(max)数据类型区别

    SQL Server中Text和varchar(max)数据类型区别   以前只知道text和image是可能被SQL Server淘汰的数据类型,但具体原因不太清楚,今天读书的时候发现了text与v ...

  2. sql动态insert向varchar(MAX)中写入据的问题

    sql动态insert向varchar(MAX)中写入据的问题,在写入时出现列无效.后来发现,varchar要加''两个,号才可以 SET @SQL='INSERT INTO '+@TabName+' ...

  3. SQL2005:使用varchar(max)代替text

    SQL Server 2005 联机丛书 中文相关说明 1.在 Microsoft SQL Server 的未来版本中将删除 ntext.text 和 image 数据类型.请避免在新开发工作中使用这 ...

  4. varchar(n)和varchar(max)有什么区别

    如果列数据项的大小一致,则使用 char. 如果列数据项的大小差异相当大,则使用 varchar. 如果列数据项大小相差很大,而且大小可能超过 8,000 字节,请使用 varchar(max).

  5. MYSQL 没有varchar(max)这个类型。

    背景: MYSQL 中不可以用varchar(max) 这种类型列来建立表 -------------------------------------------------------------- ...

  6. SQL Server中Text和varchar(max) 区别

    SQL Server 2005之后版本:请使用 varchar(max).nvarchar(max) 和 varbinary(max) 数据类型,而不要使用 text.ntext 和 image 数据 ...

  7. Frame size of 257 MB larger than max allowed 100 MB

    ActiveMQ有时会报类似Frame size of 257 MB larger than max allowed 100 MB的错误,意思是单条消息超过了预设的最大值,在配置文件中 <tra ...

  8. MS SQL大值数据类型varchar(max)、nvarchar(max)、varbinary(max)

    在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max).nvarchar(max).varbinary(max) ).大值数据类型最多可以存储2^30-1个字节的数据. 这几 ...

  9. 关于varchar(max), nvarchar(max)和varbinary(max)

    在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max).nvarchar(max).varbinary(max) ).大值数据类型最多可以存储2^30-1个字节的数据.这几个 ...

随机推荐

  1. python函数的参数-可变参数,关键字参数

    # -*- coding: utf-8 -*- #coding=utf-8 ''' @author: tomcat @license: (C) Copyright 2017-2019, Persona ...

  2. python/pandas 正则表达式 re模块

    目录 正则解说 中文字符集 re模块常用方法 1.正则解说 数量词的贪婪模式与非贪婪模式 正则表达式通常用于在文本中查找匹配的字符串.Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪) ...

  3. Map-Amap:货运解决方案

    ylbtech-Map-Amap:货运解决方案 1.返回顶部 1. http://lbs.amap.com/smart/truck/ 2. 2.返回顶部 1. 2. 3.返回顶部   4.返回顶部   ...

  4. 多级xml解析方案

    package com.people.xmlToSql; import java.io.File; import java.io.IOException; import java.io.StringW ...

  5. webapi返回json格式优化 转载https://www.cnblogs.com/GarsonZhang/p/5322747.html

    一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 1 config.Formatters.Remove(config.F ...

  6. 返回闭包不能引用循环变量,请改写count()函数,让它正确返回能计算1x1、2x2、3x3的函数。

    错误写法: 正确写法:

  7. PAT_A1071#Speech Patterns

    Source: PAT A1071 Speech Patterns (25 分) Description: People often have a preference among synonyms ...

  8. MSF——基本使用和Exploit模块(一)

    MSF系列: MSF——基本使用和Exploit模块(一) MSF——Payload模块(二) MSF——Meterpreter(三) MSF——信息收集(四) MSF——Metasploit Fra ...

  9. python-javascript之dom

    DOM DOM:(document object mode)文档对象模型.DOM为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构. 目的就是为了能让js操作html元素而制定的一个规范 DO ...

  10. Scrapy框架: 异常错误处理

    import scrapy from scrapy.spidermiddlewares.httperror import HttpError from twisted.internet.error i ...