1. 程式人生 > >查詢資料庫並且將查詢到的資料生成一個數組

查詢資料庫並且將查詢到的資料生成一個數組

    public class shuzulei
    {
        private double x;
        private double y;
        public double zhix
        {
            set { this.x = value; }
            get { return this.x; }


        }
        public double zhiy
        {
            set { this.y = value; }
            get { return this.y; }
        }
    }

 private shuzulei[] shuzu()

        {
            shuzulei[] a = new shuzulei[155280];
            String conn = "Data Source=WEINIU;Initial Catalog=sde;Persist Security Info=True;User ID=sa;Password=m";
            SqlConnection connection = new SqlConnection(conn);
            string sql = "select * from AAA";






            connection.Open();
            SqlCommand command = new SqlCommand(sql, connection);


            SqlDataReader sdr = command.ExecuteReader();
            int i = 0;
            while (sdr.Read())
            {


                double X1 = Convert.ToDouble(sdr["X"]);
                double Y1 = Convert.ToDouble(sdr["Y"]);
                a[i] = new shuzulei();
                a[i].zhix = X1;
                a[i].zhiy = Y1;




                i++;
            }


            sdr.Close();
            connection.Close();
            return a;




        }