当前位置:操作系统 > Unix/Linux >>

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

 

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("</br>");

                                   }

                                   else

                                   {

                                       Response.Write(list[i]);

                                   }

                               }

                        }

                    }

                }

            }

        }

    }

}

摘自 haitaoDoit的专栏

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,