[csharp] using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
cmd
cmd
cmd
conn
SqlDataReader rdr = cmd
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
}
finally
{
conn
}
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
}
}
using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
cmd
cmd
cmd
conn
SqlDataReader rdr = cmd
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
}
finally
{
conn
}
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
}
}
二
[csharp] using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlCommand cmd = new SqlCommand()
//簡單地說
using(SqlConnection conn = new SqlConnection(connectionString))
{
cmd
cmd
cmd
conn
SqlDataReader rdr = cmd
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
}
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
}
}
using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlCommand cmd = new SqlCommand()
//簡單地說
using(SqlConnection conn = new SqlConnection(connectionString))
{
cmd
cmd
cmd
conn
SqlDataReader rdr = cmd
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
}
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
}
}
三
[csharp] using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlDataReader rdr = ExecuteReader(connectionString
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
public static SqlDataReader ExecuteReader(string connectionString
{
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
cmd
cmd
cmd
conn
[nextpage]
//如果創建了 SqlDataReader 並將 CommandBehavior 設置為 CloseConnection
//則關閉 SqlDataReader 會自動關閉此連接
SqlDataReader rdr = cmd
return rdr;
}
catch
{
conn
throw;
}
//finally
//{
// conn
//}
}
}
}
using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlDataReader rdr = ExecuteReader(connectionString
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
public static SqlDataReader ExecuteReader(string connectionString
{
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
cmd
cmd
cmd
conn
//如果創建了 SqlDataReader 並將 CommandBehavior 設置為 CloseConnection
//則關閉 SqlDataReader 會自動關閉此連接
SqlDataReader rdr = cmd
return rdr;
}
catch
{
conn
throw;
}
//finally
//{
// conn
//}
}
}
}
[nextpage]
四
[csharp] using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlDataReader rdr = ExecuteReader(connectionString
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
public static SqlDataReader ExecuteReader(string connectionString
{
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
//cmd
//cmd
//cmd
//conn
PrepareCommand(cmd
//如果創建了 SqlDataReader 並將 CommandBehavior 設置為 CloseConnection
//則關閉 SqlDataReader 會自動關閉此連接
SqlDataReader rdr = cmd
cmd
return rdr;
}
catch
{
conn
throw;
}
//finally
//{
// conn
//}
}
private static void PrepareCommand(SqlCommand cmd
{
if (conn
conn
cmd
cmd
if (trans != null)
cmd
cmd
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
cmd
}
}
}
}
using System;
using System
using System
using System
using System
using WestGarden
namespace WestGarden
{
public partial class Default
{
protected void Page_Load(object sender
{
[nextpage]
IList<CategoryInfo> catogories = new List<CategoryInfo>()
string connectionString = ConfigurationManager
string cmdText =
SqlDataReader rdr = ExecuteReader(connectionString
while (rdr
{
CategoryInfo category = new CategoryInfo(rdr
catogories
}
rdr
ddlCategories
ddlCategories
ddlCategories
ddlCategories
}
public static SqlDataReader ExecuteReader(string connectionString
{
SqlCommand cmd = new SqlCommand()
SqlConnection conn = new SqlConnection(connectionString)
try
{
//cmd
//cmd
//cmd
//conn
PrepareCommand(cmd
//如果創建了 SqlDataReader 並將 CommandBehavior 設置為 CloseConnection
//則關閉 SqlDataReader 會自動關閉此連接
SqlDataReader rdr = cmd
cmd
return rdr;
}
catch
{
conn
throw;
}
//finally
//{
// conn
//}
}
private static void PrepareCommand(SqlCommand cmd
{
[nextpage]
if (conn
conn
cmd
cmd
if (trans != null)
cmd
cmd
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
cmd
}
}
}
}
五
[html] <asp:Repeater ID=
<HeaderTemplate>
<table cellspacing=
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink runat=
Text=
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater ID=
<HeaderTemplate>
<table cellspacing=
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink runat=
Text=
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
[csharp] repCategories
repCategories
From:http://tw.wingwit.com/Article/program/net/201311/13382.html