IndexOutOfRangeException
class Program
{
static void Main(string[] args)
{
string Str = "Persist Security Info=False;Initial Catalog=Northwind;";
Str += "Data Source=localhost;Integrated Security=SSPI;";
SqlConnection con = new SqlConnection(Str);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "EmployeeCount";
com.Parameters.Add("@City", SqlDbType.NVarChar, 15);
com.Parameters["@city"].Value = "London";
com.Parameters.Add("@City", SqlDbType.Int);
com.Parameters["@Count"].Direction = ParameterDirection.Output;
con.Open();
SqlDataReader rd = com.ExecuteReader();
Console.WriteLine("{0}\t{1}", rd.GetName(0), rd.GetName(1));
while (rd.Read())
{
Console.WriteLine("{0}\t,\t{1}", rd.GetString(0), rd.GetString(1));
}
rd.NextResult();
Console.WriteLine("{0}", com.Parameters["@Count"].Value);
rd.Close();
con.Close();
}
}
问题就是这行 com.Parameters["@Count"].Direction = ParameterDirection.Output;
异常如题 哪个大哥帮忙解决下