我使用VSTS 2008 + C#+ .net 3.5 + ADO.Net。這是我的代碼和相關的錯誤消息。錯誤消息說,@ Param1不提供,但實際上它是在我的代碼中提供的。任何想法有什麼不對?錯誤調用存儲過程與輸入參數從ADO.Net
System.Data.SqlClient.SqlException: 過程或函數 'Pr_Foo' 預計 參數 '@參數1',這是不 供給。
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);
}
}
}
由於提前,
喬治
你似乎已經消毒的代碼張貼在看不一致的參數名稱。我懷疑你對代碼的清理已經隱藏了實際的問題。你可以仔細檢查你做了什麼? – 2010-06-07 16:16:55
你是什麼意思「檢查你做了什麼」?感謝您能否提供更多關於檢查內容的細節? :-) – George2 2010-06-07 16:19:40
你有'SqlParameter Param2 = _command .....',然後下一行讀取'portal_SiteInfoID.Direction = ....' - 應該是相同的參數'Param2'? – 2010-06-07 16:23:31