Я использую VSTS 2008 + C # + .Net 3.5 + ADO.Net.Вот мой код и соответствующее сообщение об ошибке.Сообщение об ошибке гласит: @ Param1 не предоставляется, но на самом деле он указан в моем коде.Любые идеи, что не так?
System.Data.SqlClient.SqlException: Процедура или функция 'Pr_Foo' ожидает параметр '@ Param1', который не был предоставлен.
class Program
{
private static SqlCommand _command;
private static SqlConnection connection;
private static readonly string _storedProcedureName = "Pr_Foo";
private static readonly string connectionString = "server=.;integrated Security=sspi;initial catalog=FooDB";
public static void Prepare()
{
connection = new SqlConnection(connectionString);
connection.Open();
_command = connection.CreateCommand();
_command.CommandText = _storedProcedureName;
_command.CommandType = CommandType.StoredProcedure;
}
public static void Dispose()
{
connection.Close();
}
public static void Run()
{
try
{
SqlParameter Param1 = _command.Parameters.Add("@Param1", SqlDbType.Int, 300101);
Param1.Direction = ParameterDirection.Input;
SqlParameter Param2 = _command.Parameters.Add("@Param2", SqlDbType.Int, 100);
portal_SiteInfoID.Direction = ParameterDirection.Input;
SqlParameter Param3 = _command.Parameters.Add("@Param3", SqlDbType.Int, 200);
portal_RoleInfoID.Direction = ParameterDirection.Input;
_command.ExecuteScalar();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
static void Main(string[] args)
{
try
{
Prepare();
Thread t1 = new Thread(Program.Run);
t1.Start();
t1.Join();
Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\t" + ex.StackTrace);
}
}
}
Заранее спасибо,
Джордж