C#数据适配器参数

Zee*_*eeV 2 c# sql

我写了一些代码来从我的数据库中获取一些数据.在stored procedure只使用ID作为参数,并使用它来筛选结果.我已经运行了stored procedure使用EXEC命令SSMS,它的工作原理.但是,当我尝试使用底部的代码调用它时,它失败了,说我没有提供参数.谁能看到我做错了什么?

using (SqlConnection sqlConnect = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{       
    try
    {
        DataTable dtBets = new DataTable("All Bets");
        using (SqlDataAdapter sqlDA = new SqlDataAdapter("up_Select_all", sqlConnect))
        {
            sqlDA.SelectCommand.Parameters.Add("@ID", SqlDbType.BigInt).Value = pCustomer.CustomerID;

            sqlDA.Fill(dtBets);
            return dtBets;
        }                        
    }

    catch (SqlException ex)
    {
        //catch code
    }
Run Code Online (Sandbox Code Playgroud)

Tim*_*ter 7

你忘了告诉DataAdapter它应该叫Stored-Procedure:

using (SqlDataAdapter sqlDA = new SqlDataAdapter("up_Select_all", sqlConnect))
{
    sqlDA.SelectCommand.CommandType = CommandType.StoredProcedure;
    sqlDA.SelectCommand.Parameters.Add("@ID", SqlDbType.BigInt).Value = pCustomer.CustomerID;

    sqlDA.Fill(dtBets);
    return dtBets;
}    
Run Code Online (Sandbox Code Playgroud)