带存储过程的查询返回空

时间:2014-01-09 11:26:46

标签: c# sql odbc sybase

下面的运行查询成功显示返回的结果;

sp_wts_lst_mod_amp_mtx 'xxxx', '062306', 'LS-I', 'EA', null

所以我正确地将与参数相同的值传递给下面的方法,但它返回空。 reader.Read()是假的。

我的方法有什么问题?

public static List<string> GetMatrices(object userMarketId, string userMarketLabelId, string model, string amp)
{
    var matrices = new List<string>();
    var connection = new OdbcConnection();
    try
    {
        using (connection = clsWTSCommon.GetDBConnection(userMarketId, null))
        using (var command = connection.CreateCommand())
        {
            command.CommandText = "{CALL " + StoreProcedures.SpWtsLstModAmpMtx + " (?,?,?,?,?)}";
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add("@ctl_mkt_id", OdbcType.NVarChar, 10).Value = userMarketId.ToString();
            command.Parameters.Add("@ctl_mkt_lbl_id", OdbcType.NVarChar, 10).Value = userMarketLabelId;
            command.Parameters.Add("@model_code", OdbcType.NVarChar, 16).Value = model;
            command.Parameters.Add("@amp_code", OdbcType.NVarChar, 3).Value = amp;
            command.Parameters.Add("@language_id", OdbcType.NVarChar, 3).Value = null;

            if (connection.State == ConnectionState.Open)
            {
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    matrices.Add(reader.GetString(reader.GetOrdinal("sspl")) + "/" +
                                 reader.GetString(reader.GetOrdinal("peak_gain")));
                }
            }
        }
    }
    catch (Exception ex)
    {
        clsDataAccess.ShowInfo(ex.Message);
    }
    finally
    {
        connection.Close();
        connection.Dispose();
    }

    return matrices;
}

1 个答案:

答案 0 :(得分:1)

这一行:

command.CommandText = "{CALL " + StoreProcedures.SpWtsLstModAmpMtx + " (?,?,?,?,?)}";

应该是:

command.CommandText = StoreProcedures.SpWtsLstModAmpMtx;

干杯 -