把数据库的内容添加到ArryList中并显示出来

2014-11-24 07:47:56 ? 作者: ? 浏览: 3

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

using System.Collections;

using System.Data;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string sql = ConfigurationManager.ConnectionStrings["strsql"].ConnectionString;

using (SqlConnection sqlCnn=new SqlConnection(sql))

{

using (SqlCommand sqlCmm=sqlCnn.CreateCommand())

{

sqlCmm.CommandText = "select * from orders";

sqlCnn.Open();

using (SqlDataReader reader = sqlCmm.ExecuteReader())

{

if (reader!=null)

{

while (reader.Read())

{

ArrayList list=new ArrayList();

list.Add(reader["id"]);

list.Add(reader["pid"]);

list.Add(reader["pname"].ToString());

list.Add(reader["pnums"]);

for (int i = 0; i < list.Count; i++)

{

if ((i + 1) % 4 == 0)

{

Response.Write("
");

}

else

{

Response.Write(list[i]);

}

}

}

}

}

}

}

}

}

摘自 haitaoDoit的专栏

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: