本文整理汇总了C#中System.Data.SqlClient.SqlParameter.ParameterName属性的典型用法代码示例。如果您正苦于以下问题:C# SqlParameter.ParameterName属性的具体用法?C# SqlParameter.ParameterName怎么用?C# SqlParameter.ParameterName使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Data.SqlClient.SqlParameter
的用法示例。
在下文中一共展示了SqlParameter.ParameterName属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddSqlParameter
private static void AddSqlParameter(SqlCommand command)
{
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@Description";
parameter.IsNullable = true;
parameter.DbType = DbType.String;
parameter.Direction = ParameterDirection.Output;
command.Parameters.Add(parameter);
}
示例2: Main
//引入命名空间
using System;
using System.Data;
using System.Data.SqlClient;
class MainClass
{
public static void Main()
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = @"Data Source = .\sqlexpress;Database = Northwind; Integrated Security=SSPI";
con.Open();
string employeeID = "5";
string title = "Cleaner";
using (SqlCommand com = con.CreateCommand())
{
com.CommandType = CommandType.Text;
com.CommandText = "UPDATE Employee SET Title = @title" +
" WHERE Id = @Employeeid";
// Create a SqlParameter object for the title parameter.
SqlParameter p1 = com.CreateParameter();
p1.ParameterName = "@title";
p1.SqlDbType = SqlDbType.VarChar;
p1.Value = title;
com.Parameters.Add(p1);
// Use a shorthand syntax to add the id parameter.
com.Parameters.Add("@Employeeid", SqlDbType.Int).Value = employeeID;
// Execute the command and process the result.
int result = com.ExecuteNonQuery();
if (result == 1)
{
Console.WriteLine("Employee {0} title updated to {1}.",
employeeID, title);
}
else
{
Console.WriteLine("Employee {0} title not updated.",
employeeID);
}
}
}
}
}