首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请大伙帮忙看一下sdr.Read();这个的有关问题!不够+++分!帮忙的哥们来

2012-01-03 
请大伙帮忙看一下sdr.Read()这个的问题!不够+++分!帮忙的哥们来!问题出现在if(sdr.Read())这个地方!这个

请大伙帮忙看一下sdr.Read();这个的问题!不够+++分!帮忙的哥们来!
问题出现在if(   sdr.Read()   )这个地方!这个我判断了如果能读读取出来!
但是它和下面的while(   sdr.Read()   )发生冲突程序不出现错误,但是while的地方“指向”数据库第二条数据,我怎么才能让他指在第一条数据上呢??
程序源码如下:
————————————————
SqlConnection   con   =   showclass.datacon.AutoCon();
con.Open();

SqlCommand   cmd   =   new   SqlCommand( "SelectDealer ",con);
cmd.CommandType   =   CommandType.StoredProcedure;

SqlParameter   uid   =   new   SqlParameter( "@pid ",SqlDbType.Int,4);
uid.Value   =   Convert.ToInt32(   pid   );
cmd.Parameters.Add(   uid   );

SqlDataReader   sdr   =   cmd.ExecuteReader();

System.Text.StringBuilder   Jxs   =   new   System.Text.StringBuilder();

if(   sdr.Read()   )
{
Jxs.Append( " <table   cellpadding=\ "0\ "   cellspacing=\ "0\ "   class=\ "pplj-gd\ "> ");
Jxs.Append( " <tr> ");
Jxs.Append( " <td   class=\ "zi\ "> 首   页   &gt;   "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ "   经销商列表   &gt;   "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ " ");
Jxs.Append( " </td> ");
Jxs.Append( " </tr> ");
Jxs.Append( " </table> ");
Jxs.Append( " <div   id=\ "pplj-1\ "> ");
Jxs.Append( " <div   class=\ "ppljzuo\ "> [ "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ "]经销商 </div> ");
Jxs.Append( " <div   class=\ "ppljyou\ "> (共 <span   class=\ "zi\ "> 17 </span> 家)&nbsp; </div> ");
Jxs.Append( " </div> ");


while(   sdr.Read()   )
{
Jxs.Append( " <table   cellpadding=\ "0\ "   cellspacing=\ "0\ "   class=\ "pplj-5\ "> ");
Jxs.Append( " <tr> ");
Jxs.Append( " <td   class=\ "pplj-6\ "> <span   class=\ "pplj-zi\ "> "+sdr[ "user_dw "].ToString()+ " </span> </td> ");
Jxs.Append( " <td   class=\ "pplj-6-1\ "> "+sdr[ "user_dz "].ToString()+ " </td> ");
Jxs.Append( " <td   class=\ "pplj-6-2\ "> <a   href=\ " "+sdr[ "user_main "].ToString()+ "\ "> 详细&gt;&gt; </a> </td> ");
Jxs.Append( " </tr> ");
Jxs.Append( " </table> ");
}
}

cmd.Dispose();
sdr.Close();
con.Close();
con.Dispose();
return   Jxs.ToString();

[解决办法]
应该直接while( sdr.Read() ),因为sdr是只向前的,不能后退的!!!
[解决办法]
bool flag = true;

while( sdr.Read() )
{
if(flag)
{
Jxs.Append( " <table cellpadding=\ "0\ " cellspacing=\ "0\ " class=\ "pplj-gd\ "> ");
Jxs.Append( " <tr> ");
Jxs.Append( " <td class=\ "zi\ "> 首 页 &gt; "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ " 经销商列表 &gt; "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ " ");


Jxs.Append( " </td> ");
Jxs.Append( " </tr> ");
Jxs.Append( " </table> ");
Jxs.Append( " <div id=\ "pplj-1\ "> ");
Jxs.Append( " <div class=\ "ppljzuo\ "> [ "+sdr[ "autobrand "].ToString()+ " "+sdr[ "autotype "].ToString()+ "]经销商 </div> ");
Jxs.Append( " <div class=\ "ppljyou\ "> (共 <span class=\ "zi\ "> 17 </span> 家)&nbsp; </div> ");
Jxs.Append( " </div> ");
flag = false;
}


Jxs.Append( " <table cellpadding=\ "0\ " cellspacing=\ "0\ " class=\ "pplj-5\ "> ");
Jxs.Append( " <tr> ");
Jxs.Append( " <td class=\ "pplj-6\ "> <span class=\ "pplj-zi\ "> "+sdr[ "user_dw "].ToString()+ " </span> </td> ");
Jxs.Append( " <td class=\ "pplj-6-1\ "> "+sdr[ "user_dz "].ToString()+ " </td> ");
Jxs.Append( " <td class=\ "pplj-6-2\ "> <a href=\ " "+sdr[ "user_main "].ToString()+ "\ "> 详细&gt;&gt; </a> </td> ");
Jxs.Append( " </tr> ");
Jxs.Append( " </table> ");

}

热点排行