求大神帮忙修改并指导
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();
}
}