這裏是我的Web方法我想補充的所有會議,我allmeeting
列表,然後我想退貨,並通過劍道電網接收如何使用SqlDataReader獲取多個記錄?
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
到第一排,每次迭代僅供參考,並不去第二在allmeetinglist()
和連接時間增加了
舉動'DefMeetingDTO d =新DefMeetingDTO();'到內環 –
任何目的的使用** reader.NextResult()**。你執行兩個查詢嗎? – shreesha
不僅1個查詢,但讀者只運行1次然後再次運行並返回第一條記錄10次,然後連接超時 –