这是我的代码:
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;
}
IService:
[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。
为什么?