作者retsamsu (haha)
看板C_Sharp
标题Re: [问题] bind SqlDataReader to GridView ?
时间Wed Aug 27 11:23:39 2008
※ 引述《maxi326 (我在新竹找工作中)》之铭言:
: 我想问 我想显示资料库的资料在网页上
: 基本上我是这样做
: pseudocode
: new SqlConnection()
: connection.open()
: connection.createCommand()
: new SqlDataReader() = connection.executeReader()
: 然後可以bind return回来的datareader给gridview
: 然後再close reader, close connection
: 但我想说做一个method, return一个data回来
: 这个method本身会close reader和connection.
: 就是把顺序倒过来
: 然後再把data用gridview之类的显示出来
: 不知道有没有办法这样做呢?
: 因为想说这样可以避免我做出一个会open connection的method
: 但有人用完之後忘记close
: 谢谢大家
1. 用SqlDataAdapter可以不会怕忘了close
2. 写一个method用executeReader的话,要先clone出一个SqlDataReader的instance
->close reader/connection->return cloned SqlDataReader instance
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.209.141
1F:推 maxi326:谢谢啦,我也在想clone行不行,我试试看喔 08/27 15:21