IDataAdapter.GetFillParameters 方法

定义

获取当执行 SQL SELECT 语句时由用户设置的参数。

public:
 cli::array <System::Data::IDataParameter ^> ^ GetFillParameters();
public System.Data.IDataParameter[] GetFillParameters ();
abstract member GetFillParameters : unit -> System.Data.IDataParameter[]
Public Function GetFillParameters () As IDataParameter()

返回

IDataParameter 对象的数组,这些对象包含由用户设置的参数。

示例

private static void GetParameters(string connectionString)
{
    using (var conn = new SqlConnection(connectionString))
	{
        var queryString = "SELECT [CourseID],[Title],[Credits] FROM [MySchool].[dbo].[Course] WHERE [Year]=@Year AND [Credits]>=@Credits";
	    var year = new SqlParameter("@Year", 2012);
	    var credits = new SqlParameter("@Credits", SqlDbType.Int, 4, "Credits");
	    credits.Value = 4;
		var command = new SqlCommand(queryString, conn);
	    command.Parameters.Add(year);
	    command.Parameters.Add(credits);
	    IDbDataAdapter mySchool = new SqlDataAdapter(command);
	    IDataParameter[] parameters = mySchool.GetFillParameters();
	    Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "ParameterName", "SourceColumn", "Direction", "DbType", "Value");
	    foreach (IDataParameter parameter in parameters)
		{
		    Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", parameter.ParameterName, parameter.SourceColumn, parameter.Direction, parameter.DbType, parameter.Value);
	    }
    }
}

适用于