| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 577 人关注过本帖
标题:求大神帮忙修改并指导
只看楼主 加入收藏
爱的吻
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: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册: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
快速回复:求大神帮忙修改并指导
数据加载中...
 
   



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

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