标题:求大神帮忙修改并指导
只看楼主
爱的吻
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2015-1-19
结帖率:0
已结贴  问题点数:20 回复次数:2 
求大神帮忙修改并指导
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();
    }
}
搜索更多相关主题的帖子: Desktop lenovo excel C语言 Users 
2015-01-20 00:12
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:10 
鬼知道你想干嘛

DO IT YOURSELF !
2015-01-20 08:40
lxsxd
Rank: 5Rank: 5
等 级:贵宾
威 望:14
帖 子:153
专家分:357
注 册:2014-4-15
得分:10 
问题呢?

艰难地走在C#自学的路上…………
2015-01-20 16:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-441277-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.505569 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved