这是我的网络方法我想在我的allmeeting
列表中添加所有会议然后我想返回它并通过kendo网格接收
List<DefMeetingDTO> AllDefCompany = new List<DefMeetingDTO>();
List<DefMeetingDTO> f = new List<DefMeetingDTO>();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
DefMeetingDTO d = new DefMeetingDTO();
int ji = reader.FieldCount;
do
{
while (reader.Read())
{
//for(int i = 0 ; i < ji ; i++) {
if (!reader.IsDBNull(reader.GetOrdinal("md_id")))
{
d.md_id = Convert.ToInt32(reader["md_id"]) as int? ?? default(int);
}
else
{
d.md_id = 0;
}
if (!reader.IsDBNull(reader.GetOrdinal("md_visitor_name")))
{
d.md_visitor_name = (string)(reader["md_visitor_name"]);// as DateTime? ?? default(DateTime);
}
else
{
// d.m_datetime = null;
}
if (!reader.IsDBNull(reader.GetOrdinal("md_visitor_cell")))
{
d.md_visitor_cell = (reader["md_visitor_cell"]).ToString();// as string? ?? default(string);
}
if (!reader.IsDBNull(reader.GetOrdinal("md_visitor_company")))
{
d.md_visitor_company = (string)reader["md_visitor_company"];
}
if (!reader.IsDBNull(reader.GetOrdinal("purpose_name")))
{
d.purpose_name = (string)reader["purpose_name"];
}
if (!reader.IsDBNull(reader.GetOrdinal("m_datetime")))
{
d.m_datetime = Convert.ToDateTime(reader["m_datetime"]) as DateTime? ?? default(DateTime);
}
AllDefCompany.Add(d);
}
}
while(reader.NextResult());
}
我的SQL查询返回结果为已检查的4行
10878 | Wasim Riaz | 0300449436 | Jade | N/A | NULL
71123 | bb | +9232531256 | F | mee | 2015-09-03
71124 | CC | +923218531256 | Fb | N/A | 2015-09-03
71125 | DD | +923218531256 | Gb | N/A | 2015-09-03
但是SqlDataReader
每次都只迭代到第1行,而不是第二行加入allmeetinglist()
并且连接超时
答案 0 :(得分:7)
我不确定您使用$(function() {
var message = "Don't forget us";
var original;
$(window).focus(function() {
if (original) {
document.title = original;
}
}).blur(function() {
var title = $('title').text();
if (title != message) {
original = title;
}
document.title = message;
});
});
循环的原因。您可以像这样简单地使用Do-While
循环: -
While
请注意,Read()无论如何都会将datareader推进到下一条记录,所以没有必要再次使用List<DefMeetingDTO> AllDefCompany = new List<DefMeetingDTO>();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
DefMeetingDTO d = new DefMeetingDTO();
if (!reader.IsDBNull(reader.GetOrdinal("md_id")))
{
d.md_id = Convert.ToInt32(reader["md_id"]) as int? ?? default(int);
}
else
{
d.md_id = 0;
}
AllDefCompany.Add(d);
}
。另请注意,没有必要检查NextResult
,因为如果没有更多行要提取,reader.HasRows
将返回false。
答案 1 :(得分:0)
我认为您正在datareader.try上执行**批处理Transact-SQL语句**以下代码
do
{
if (reader.HasRows)
{
while (reader.Read())
{
DefMeetingDTO d = new DefMeetingDTO();
if (!reader.IsDBNull(reader.GetOrdinal("md_id")))
{
d.md_id = Convert.ToInt32(reader["md_id"]) as int? ?? default(int);
}
else
{
d.md_id = 0;
}
AllDefCompany.Add(d);
}
}
}
while(reader.NextResult());