注册 登录
编程论坛 C# 论坛

求大神帮忙修改并指导

爱的吻 发布于 2015-01-20 00:12, 577 次点击
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C语言作业
{
    class Program
    {a
        static void Main(string[] args)
        {
            string[,] ary = new string[10, 13];
            //read data from excel
            try
            {
                string file = @"C:\Users\lenovo\Desktop\info.xls";
               SqlConnection myconn = new SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0.Extended properties=Excel 8.0");
              
               SqlCommand conn = new SqlCommand("Select * from [sheet1$])");
               SqlDataReader re = conn.ExecuteReader();
                 myconn.Open();
               if (re != null)
               {
                   int i =0;
                   //read data to 2-dimention matris
                   while (re.Read())
                   {

                    ary[i,0] = re["ID"].ToString();
                    ary[i,1] = re["StudentNum"].ToString();
                    ary[i,2] = re["Name"].ToString();
                    ary[i,3] = re["Age"].ToString();
                    ary[i,4] = re["Gender"].ToString();
                    ary[i,5] = re["Height"].ToString();
                    ary[i,6] = re["weight"].ToString();               
                    ary[i,7] = re["VitalCapacity"].ToString();
                    ary[i,8] = re["Jump"].ToString();
                    ary[i,9] = re["Shot"].ToString();
                    ary[i,10] = re["100-meter"].ToString();
                    ary[i,11] = re["800-meter"].ToString();
                    ary[i,12] = re["Situps"].ToString();
                    
                    i++;
                 }
             }         
         }
         catch (Exception ex)
         {
            Console. WriteLine(ex.Message);
         }
         ////////////////////////////////////////////////////////////////////////////////////////////
         //sort
         int id = 4 ,//id ={1,,3,,5,6,7,8,9,10,11,12};
         Double[] data = new double[10];
         //read your data to array
         for (int i = 0; i<10; i++)
         {
           data[i] = Convert.ToDouble(ary[i,id]);
         }
         //your code
        for (int i =0; i< data.Length -1;i++)
        {
          for (int j = 0; j<4.Length -1-i;j++ )
          {
            if (data[j] >data [j+1])
             {
               double temp =data [j];
               data[j] = data[j+1];
               data[j+1] = temp;
              }
           }
         }
         //print resuly
         for (int i =0, i < data.Length , i++)
         {
             Console.WriteLine(data[i]);
         }
         Console. WriteLine("finished");
         Console. ReadKey();
    }
}
2 回复
#2
wp2319572015-01-20 08:40
鬼知道你想干嘛
#3
lxsxd2015-01-20 16:00
问题呢?
1