C# linqToSQL datetime从表中获取最新数据

C# linqToSQL datetime从表中获取最新数据,c#,linq,linq-to-sql,.net-3.5,ssis,C#,Linq,Linq To Sql,.net 3.5,Ssis,您好,我正在尝试使用LinqToSQL从表中获取最大时间日期。我已经问了一个类似的问题,但我正试图做一些更具体的事情,没有人能帮忙。这次,除了SSIS包的另一部分中的执行SQL任务之外,我不介意使用任何解决方案。这是我的全部密码。我只是想得到身份栏,但它根本不起作用,所以请忽略ToString,如果它看起来不合适的话。我只想得到最新创建的时间戳 using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime; usin

您好,我正在尝试使用LinqToSQL从表中获取最大时间日期。我已经问了一个类似的问题,但我正试图做一些更具体的事情,没有人能帮忙。这次,除了SSIS包的另一部分中的执行SQL任务之外,我不介意使用任何解决方案。这是我的全部密码。我只是想得到身份栏,但它根本不起作用,所以请忽略ToString,如果它看起来不合适的话。我只想得到最新创建的时间戳

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
using System.Linq;
using System.Data.SqlClient;
using System.Linq.Expressions;
using System.Collections;
using System.Collections.Generic;
using System.Data.Linq.Mapping;
using System.Data.Linq;



namespace ST_663004ffff194a14b84e2291578ada33.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion


            //Strings for connections
            string iFileName; 
            string oFileName;
            string RW;


        public void Main()
        {
            Dts.Variables["latestTableRow"].Value = getLatest();

            MessageBox.Show(getLatest());

            Dts.TaskResult = (int)ScriptResults.Success;

        }// End Main

        public string getLatest()
        {
            string result = "";

            ////temp dummy/defaul date is two days ago
            //DateTime result = new DateTime();   
            //result = DateTime.Now.AddDays(-2);

            try
            {
                //get the data connection string from the connection manager
                RW = (string)Dts.Connections["ReportingWarehouse"].ConnectionString;

                //Remove the Provider, Auto Translate, and Application
                //as it is not a parameter for the DataContext constructor
                RW = RW.Remove(RW.IndexOf("Provider=SQLNCLI10.1;"), "Provider=SQLNCLI10.1;".Length);
                RW = RW.Remove(RW.IndexOf("Auto Translate=False;"), "Provider=SQLNCLI10.1;".Length);
                RW = RW.Remove(RW.IndexOf("Application"),RW.Length - RW.IndexOf("Application"));



                MessageBox.Show(RW);

                //get the last insertion date from the SSASLoging table
                using (DataContext RWData = new DataContext(RW))
                {

                    Table<SSASLogging> records = RWData.GetTable<SSASLogging>();
                    var rs = (from r in records
                              orderby r.TimeStamp descending
                              select r).Max();
                    result = rs.Errorval.ToString();
                }

                MessageBox.Show(result);

            }

            catch (Exception e)
            {
                MessageBox.Show("Exception in retreiving latest time: " + e.Message + "/n"
                                + e.StackTrace);
            }

            return result;
       }

    }//end partial class


    [Table(Name = "SSASLogging")]
    public class SSASLogging
    {

        private DateTime timeStamp;

        [Column(Name = "CREATED_TIMESTAMP")]
        public DateTime TimeStamp
        {
            get { return this.timeStamp; }
            private set { ;}
        }
    }//End SSASLogging
}
好的,这个有效

            using (DataContext RWData = new DataContext(RW))
            {
                Table<SSASLogging> records = RWData.GetTable<SSASLogging>();
                var rs = (from r in records
                          select r).Max(r => r.TimeStamp);
                result = rs;
            }