0

这是我的代码:

public List<Remarks1> fillRemarks1List(RemarksRequest oei)
{
    List<Remarks1> mylist = new List<Remarks1>();
    SqlConnection sqlConn = new SqlConnection(strConn);
    sqlConn.Open();
    SqlCommand commInfo = new SqlCommand();
    commInfo.CommandType = CommandType.StoredProcedure;
    commInfo.CommandText = "dbo.SPQueryRemList";
    commInfo.Connection = sqlConn;

    commInfo.Parameters.Add(new System.Data.SqlClient.SqlParameter("@reqNo", System.Data.SqlDbType.Char, 20));
    commInfo.Parameters["@reqNo"].Value = "0200000458";//oei.reqNo1.ToString().Trim();
    commInfo.Parameters.Add(new System.Data.SqlClient.SqlParameter("@lgnId", System.Data.SqlDbType.Char, 10));
    commInfo.Parameters["@lgnId"].Value = oei.loginid.ToString().Trim();

    SqlDataReader rdr4;
    try
    {
        rdr4 = commInfo.ExecuteReader();

        while (rdr4.Read())
        {
            mylist.Add(new Remarks1(rdr4.GetString(7).Trim(), rdr4.GetString(8).Trim(), rdr4.GetString(0).Trim(), rdr4.GetString(5).Trim()));
        }

        rdr4.Close();
    }
    catch (Exception ex)
    {

    }
    finally
    {
        commInfo.Dispose();

    }
    sqlConn.Close();

    return mylist;
}

服务:

[OperationContract]
[WebInvoke(Method = "POST",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "remarksList")]
List<Remarks1> fillRemarks1List(RemarksRequest oei);

使用我的服务的 ajax 调用:

urlToHandler = 'http://localhost/WcfService/Service1.svc/remarksList';
    
var tempyear="";
 
$.ajax({
    url: urlToHandler,
    data:JSON.stringify({oei:{"loginid":userid}}),
    type: 'POST',
    dataType:"json",
    contentType: 'application/json',
    success: function(data) {    
        alert(data.fillRemarksListResult);
        $.each(data.fillRemarksListResult,function(key,val) {
        });
    },
    error: function(data, status, jqXHR) {                       
        alert('There was an error.');
    }
}); // end $.ajax

我收到以下错误:

rdr4.Depth 抛出 System.InvalidOperationException 类型的异常:关闭阅读器时调用 Depth 的尝试无效。

rdr4.FieldCount 抛出 System.InvalidOperationException 类型的异常:关闭阅读器时调用 FieldCount 的尝试无效。

rdr4.HasRows 引发 System.InvalidOperationException 类型的异常:关闭阅读器时调用 HasRows 的尝试无效。

为什么?

4

0 回答 0