本文整理匯總了C#中System.Data.SqlClient.SqlParameterCollection.Item屬性的典型用法代碼示例。如果您正苦於以下問題:C# SqlParameterCollection.Item屬性的具體用法?C# SqlParameterCollection.Item怎麽用?C# SqlParameterCollection.Item使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Data.SqlClient.SqlParameterCollection
的用法示例。
在下文中一共展示了SqlParameterCollection.Item屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateSqlParameters
static private string CreateSqlParameters(int documentID)
{
// Assumes GetConnectionString returns a valid connection string to the
// AdventureWorks sample database on an instance of SQL Server 2005.
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;
// Create the input parameter for the DocumentID.
SqlParameter paramID =
new SqlParameter("@DocumentID", SqlDbType.Int);
paramID.Value = documentID;
command.Parameters.Add(paramID);
// Create the output parameter to retrieve the summary.
SqlParameter paramSummary =
new SqlParameter("@DocumentSummary", SqlDbType.NVarChar, -1);
paramSummary.Direction = ParameterDirection.Output;
command.Parameters.Add(paramSummary);
// List the parameters and some of properties.
SqlParameterCollection paramCollection = command.Parameters;
string parameterList = "";
for (int i = 0; i < paramCollection.Count; i++)
{
parameterList += String.Format(" {0}, {1}, {2}\n",
paramCollection[i], paramCollection[i].DbType,
paramCollection[i].Direction);
}
Console.WriteLine("Parameter Collection:\n" + parameterList);
// Execute the stored procedure; retrieve
// and display the output parameter value.
command.ExecuteNonQuery();
Console.WriteLine((String)(paramSummary.Value));
return (String)(paramSummary.Value);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
}