-1

WCF サービスでは、Linq クラスを使用します。私のコードは次のとおりです。

AttendenceDataContext projectDataContext=new AttendenceDataContext();
var brAttendence = new BR_Attendance()
{
    SupId =1,
    AttenDate=from w in projectDataContext.gete,
    InTime =,
    OutTime =,
    ImageName =,
    ImageUrl =,
    PresentBR =,
    AbsentBR =,
    Active = true
};

コードを wcf サービスに記述します。操作コントラクト メソッド内にgetsysdatefromを挿入できます。私のwcfサービスコードは次のとおりです。

namespace ServiceHost
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UploadService
    {
        [OperationContract]
        public bool Upload(ImageFile image)
        {
            FileStream fileStream = null;
            BinaryWriter writer = null;
            string filePath;

            try
            {
                filePath = HttpContext.Current.Server.MapPath(".") + "\\Picture\\" + image.ImageName;
                if (image.ImageName != string.Empty)
                {
                    fileStream = File.Open(filePath, FileMode.Create);
                    writer = new BinaryWriter(fileStream);
                    writer.Write(image.Imagestream);
                }
                if (fileStream != null)
                    fileStream.Close();
                if (writer != null)
                    writer.Close();

                AttendenceDataContext projectDataContext = new AttendenceDataContext();
                var brAttendence = new BR_Attendance()
                {
                    SupId = 1,
                    AttenDate = from w in projectDataContext.gete,
                    InTime =,
                    OutTime =,
                    ImageName =,
                    ImageUrl =,
                    PresentBR =,
                    AbsentBR =,
                    Active = true
                };

                return true;
            }
            catch (Exception)
            {
                if (fileStream != null)
                    fileStream.Close();
                if (writer != null)
                    writer.Close();
                return false;
            }
            finally
            {
            }
        }
    }
}

AttenDateで、Microsoft SQL Server の現在の日付を取得したいと考えています入手方法は?

4

6 に答える 6

1

重複した質問のように聞こえます。

Entity Framework を使用している場合は、以下を参照してください: How to ask database server for current datetime using entity framework?

Linq to Sql を使用している場合は、Linq to SQL 式で SQL の GETDATE() と DATEADD() を使用するにはどうすればよいですか?

于 2012-12-06T12:04:26.217 に答える
0

このコード スニペットを AttendenceDataContext に記述します。

Function(Name = "GetDate", IsComposable = true)]
 public System.DateTime GetServerDate()
 {
   return ((System.DateTime)(this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue));
 }

その後

 AttenDate = AttendenceDataContext.GetServerDate();
于 2012-12-06T12:03:30.053 に答える
0
[Function(Name = "GetDate", IsComposable = true)]
public System.DateTime GetServerDate()
{
    return ((System.DateTime)(this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue));
}
于 2015-06-17T07:57:08.783 に答える
0
public DateTime getServerTime()
{
    workcalendar2Entities1 db = new workcalendar2Entities1();
    var con = db.Database.Connection;
    var cmd = con.CreateCommand();
    cmd.CommandText = "SELECT SYSDATETIME()";
    con.Open();
    var datetime = (DateTime)cmd.ExecuteScalar();
    con.Close();
    return datetime;
}

私はエンティティフレームワークで動作しているこれを使用しています

于 2018-09-10T11:10:55.310 に答える
-1

やってみました

System.DateTime.Now

これにより、現在の日付と時刻が返されます。

詳細については、次のページをご覧ください。

Date Time Now プロパティ

于 2012-12-06T11:54:19.870 に答える