adandelion

诗词在线 http:/www.chinapoesy.com


诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|现代诗歌

博客园 首页 联系 订阅 管理

asp.net c#里如何使用 varchar(max) 参数


SqlParameter paramSummary =
                new SqlParameter("@DocumentSummary",
                SqlDbType.VarChar, -1);


MSDN完整的例子:

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

Code
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;
        }
    }
}



这里有更详尽的例子:Working with Large Value Types
http://msdn.microsoft.com/en-us/library/a1904w6t(VS.80).aspx

posted on 2009-07-27 17:05  猪头  阅读(4105)  评论(0编辑  收藏  举报

欢迎访问诗词在线http://www.chinapoesy.com   诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|古典诗歌|现代诗歌|古典诗词|现代诗词|诗歌可以陶冶你的情操、丰富你的生活,让你更具内涵。诗词在线打造中国最好的诗词社区!

诗词在线社区

126在线阅读网 历史书籍、文学书籍、小说。。。