3

SQL接続を取得して接続するメソッドがあります。新しいコマンドを作成し、いくつかのパラメーターを追加してから、アダプターを実行して DataTable を埋めます。ただし、パラメーターを指定していないというエラーが表示されます-持っていることをクリアしても。

ここで何がうまくいかないと思いますか?

public static DataTable getStatsPaged(int currentPage, int pageSize, int year, int month, int day, int logType, int itemid, string stat)
{
    using (SqlConnection connection = sqldb.getSqlConnection("db2"))
    {
        connection.Open();

        using (SqlCommand command = new SqlCommand("stp_FidusTrak_"+stat+"_paged", connection))
        {
            command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", DataRowVersion.Current, null));
            command.Parameters.Add(new SqlParameter("@CurrentPage", currentPage));
            command.Parameters.Add(new SqlParameter("@PageSize", pageSize));
            command.Parameters.Add(new SqlParameter("@Year", year));
            command.Parameters.Add(new SqlParameter("@Month", month));
            command.Parameters.Add(new SqlParameter("@Day", day));
            //error is this logType
            //Procedure or function 'stp_FidusTrak_SearchParameterSelect_paged' expects parameter '@LogType', which was not supplied.
            command.Parameters.Add(new SqlParameter("@LogType", -10));
            command.Parameters.Add(new SqlParameter("@itemId", itemid));
            command.Parameters.Add(new SqlParameter("@TotalRecords", SqlDbType.Int, 4, ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "", DataRowVersion.Current, null));
            command.Parameters.Add(new SqlParameter("@FirstDate", SqlDbType.SmallDateTime, 4, ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "", DataRowVersion.Current, null));

            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
                adapter.SelectCommand = command;
                DataTable table = new DataTable();
                adapter.Fill(table);

                return table;
            }
        }
    }
}

通常は変数として渡されるのですが、そのまま-10と書いても供給されていません..

誰でもアイデアを得ましたか?私の使い方が悪いのでしょうか?

ありがとう。

4

4 に答える 4

3

コマンド タイプを指定する必要がありますStoredProcedure。こちらのドキュメントを参照してください: http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.commandtype.aspx

于 2013-10-22T09:40:51.967 に答える
2

これが呼び出しているストアド プロシージャであることをADO.NET に伝えていません。

次の行を追加します。

using (SqlCommand command = new SqlCommand("stp_FidusTrak_"+stat+"_paged", connection))
{  
    // tell it that it's a stored procedure
    command.CommandType = CommandType.StoredProcedure;
于 2013-10-22T09:42:53.453 に答える
1

コードで SP を使用する場合は、この行を挿入する必要があります。

command.CommandType = CommandType.StoredProcedure;
于 2013-10-22T09:44:51.193 に答える
0

LogTypeストアド プロシージャに渡すパラメーターの型と、既定の型StoredProcedureを取るため、コマンド オブジェクトの言及された型を確認します。Text

以下の行を試してください:-

command.Parameters.Add(new SqlParameter("@LogType", "-10"));
于 2013-10-22T09:44:38.053 に答える