sqlparamter如何传递nvarchar(max) 参数
类别:编程学习 浏览量:297
时间:2015-4-4 sqlparamter如何传递nvarchar(max) 参数
sqlparamter如何传递nvarchar(max) 参数sqlparamter中传递nvarchar(max) 参数的方法
SqlParameter paramSummary =
new SqlParameter("@DocumentSummary",
SqlDbType.VarChar, -1);
实例
1、含有nvarchar(max) 的存储过程
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
2、sqlparamter传递nvarchar(max) 参数
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;
}
}
}
标签:SqlParameter
热门推荐
- 聊天室python小程序(用Python写一个模拟qq聊天小程序的代码实例)
- sqlserver数据库如何分页(SQL server分页的4种方法示例很全面)
- dedecms优化关键词(DedeCMS栏目列表推荐文章加粗效果去除方法)
- sqlserver安装使用教程(SQL Server 2019下载与安装教程自定义安装)
- css cursor鼠标效果
- vue多个对象实现双向数据绑定(利用js实现Vue2.0中数据的双向绑定功能)
- C#中ArrayList与Array的区别
- 阿里云服务器远程连不上(阿里云服务器重置后无法远程登录解决方案)
- thinkphp兼容dedecms(DedeCMS Error:Tag disabled:"php"的解决办法)
- python豆瓣电影爬虫课程设计报告(详解python 模拟豆瓣登录豆瓣6.0)