如何最好地保存通过SQL提取的Oracle数据

时间:2018-10-23 13:14:40

标签: c# json winforms

因此,我正在一个个人项目上工作,我想从一系列Oracle表中提取数据并保存下来。 Winforms中显示的数据将是最新数据,但用户可以选择查看早期文件。

我大部分工作都是使用newtonsoft JSON包进行的,将其序列化为文件并反序列化为datadridview。

我现在想做的是从这些信息中查询并碰壁,这使我想知道JSON是否是正确的路径。也许我应该做XML或直接将数据保存到excel文件中?

我想使用这些查询到的数据来填充datagridviews,生成度量标准,图形等。

让我的问题更具体地针对JSON,因为这就是我现在的位置。 我需要从JSON文件查询。 这是我下面的代码,用于标识文件夹中的最新文件并用它填充datagridview

var directory = new DirectoryInfo(@"C:\temp\GRMReportingJSONfiles\");
        var myFile = (from f in directory.GetFiles()
                      orderby f.LastWriteTime descending
                      select f).First();

        //DataTable assgnDT = new DataTable();

        using (StreamReader file = File.OpenText(@"C:\temp\GRMReportingJSONfiles\" + myFile))
        {

            JsonSerializer serializer = new JsonSerializer();
            IEnumerable<AssgnData> movie2 = (IEnumerable<AssgnData>)serializer.Deserialize(file, typeof(IEnumerable<AssgnData>));
            //dataGridView1.DataSource = movie2;
            //AssgnData movie2 = (AssgnData)serializer.Deserialize(file, typeof(AssgnData));
            //assgnDT
        }



    }
    public class AssgnData
    {
        public string PROJ_BU { get; set; }
        public string EMPLID { get; set; }
        public string Resource_Name { get; set; }
        public string mnth1 { get; set; }
        public string mnth2 { get; set; }
    }

使LINQ查询正常工作。只显示2行而不是10

using (StreamReader file = File.OpenText(@"C:\temp\GRMReportingJSONfiles\" + myFile))
        {

            JsonSerializer serializer = new JsonSerializer();
            IEnumerable<AssgnData> movie2 = (IEnumerable<AssgnData>)serializer.Deserialize(file, typeof(IEnumerable<AssgnData>));

            dataGridView1.DataSource = (from p in movie2
                                  where p.PROJECT_ID == "111111"
                                  select p).ToArray();

            //dataGridView1.DataSource = peopleOverForty;
            //AssgnData movie2 = (AssgnData)serializer.Deserialize(file, typeof(AssgnData));
            //assgnDT
        }

1 个答案:

答案 0 :(得分:0)

使LINQ查询正常工作。只显示2行而不是10

using (StreamReader file = File.OpenText(@"C:\temp\GRMReportingJSONfiles\" + myFile))
    {

        JsonSerializer serializer = new JsonSerializer();
        IEnumerable<AssgnData> movie2 = (IEnumerable<AssgnData>)serializer.Deserialize(file, typeof(IEnumerable<AssgnData>));

        dataGridView1.DataSource = (from p in movie2
                              where p.PROJECT_ID == "111111"
                              select p).ToArray();

        //dataGridView1.DataSource = peopleOverForty;
        //AssgnData movie2 = (AssgnData)serializer.Deserialize(file, typeof(AssgnData));
        //assgnDT
    }