Simple Date Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yog

    Simple Date Question

    I am trying to update a date column in dataset from a textbox.

    When a date is changed in textbox, the dataset should reflect this,
    similarly when the textbox is cleared to null the dataset should reflect
    this. This is since i use the "DataViewRowSta te.ModifiedCurr ent" later to
    detect the changes for update.

    How do we acheive this?.

    Currently since i am ignoring nulls, i miss the null condition.
    if (this.HIRE_DT.T ext.ToString(). Trim() != ""){

    oRow["HIRE_DT"] =
    Convert.ToDateT ime(this.HIRE_D T.Text.ToString ().Trim());

    }



    Thank you,

    Yog


  • Marina

    #2
    Re: Simple Date Question

    What are you asking exactly? Howe to set a date field in a dataset to null?

    oRow["HIRE_DT"] = DBNull.Value;

    "Yog" <shiva_jm@hotma il.com> wrote in message
    news:%23MqI4%23 I2EHA.3500@TK2M SFTNGP09.phx.gb l...[color=blue]
    > I am trying to update a date column in dataset from a textbox.
    >
    > When a date is changed in textbox, the dataset should reflect this,
    > similarly when the textbox is cleared to null the dataset should reflect
    > this. This is since i use the "DataViewRowSta te.ModifiedCurr ent" later to
    > detect the changes for update.
    >
    > How do we acheive this?.
    >
    > Currently since i am ignoring nulls, i miss the null condition.
    > if (this.HIRE_DT.T ext.ToString(). Trim() != ""){
    >
    > oRow["HIRE_DT"] =
    > Convert.ToDateT ime(this.HIRE_D T.Text.ToString ().Trim());
    >
    > }
    >
    >
    >
    > Thank you,
    >
    > Yog
    >
    >[/color]


    Comment

    • Yog

      #3
      Re: Simple Date Question

      Thanks Marina, partly yes.

      But my aim is to reduce the number of DB calls, and do an update only when a
      change is detected.

      If I have the code the following way,

      if (this.HIRE_DT.T ext.ToString(). Trim() != ""){
      oRow["HIRE_DT"] = Convert.ToDatei
      Time(this.HIRE_ DT.Text.ToStrin g().Trim());
      }else{
      oRow["HIRE_DT"] = DBNull.Value;
      }

      Assuming the date in the HIRE_DT textbox was null initially, since i am
      setting an explicit DBNull.Value here again, even though the user doesn't do
      anything in the UI, the program will set a DBNull.Value and the dataset
      detects a change

      ie.
      ds.HasChanges() will detect a change, and DataViewRowStat e.ModifiedCurre nt
      will do an extra DB call.

      Thank you,
      Yog

      "Marina" <someone@nospam .com> wrote in message
      news:%231nnACJ2 EHA.3820@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > What are you asking exactly? Howe to set a date field in a dataset to[/color]
      null?[color=blue]
      >
      > oRow["HIRE_DT"] = DBNull.Value;
      >
      > "Yog" <shiva_jm@hotma il.com> wrote in message
      > news:%23MqI4%23 I2EHA.3500@TK2M SFTNGP09.phx.gb l...[color=green]
      > > I am trying to update a date column in dataset from a textbox.
      > >
      > > When a date is changed in textbox, the dataset should reflect this,
      > > similarly when the textbox is cleared to null the dataset should reflect
      > > this. This is since i use the "DataViewRowSta te.ModifiedCurr ent" later[/color][/color]
      to[color=blue][color=green]
      > > detect the changes for update.
      > >
      > > How do we acheive this?.
      > >
      > > Currently since i am ignoring nulls, i miss the null condition.
      > > if (this.HIRE_DT.T ext.ToString(). Trim() != ""){
      > >
      > > oRow["HIRE_DT"] =
      > > Convert.ToDateT ime(this.HIRE_D T.Text.ToString ().Trim());
      > >
      > > }
      > >
      > >
      > >
      > > Thank you,
      > >
      > > Yog
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Marina

        #4
        Re: Simple Date Question

        In this case, check if the value in the dataset is already the same as what
        you want to set it too. If it is, don't do anything. Otherwise do the set.

        "Yog" <shiva_jm@hotma il.com> wrote in message
        news:uwNZBfK2EH A.3840@tk2msftn gp13.phx.gbl...[color=blue]
        > Thanks Marina, partly yes.
        >
        > But my aim is to reduce the number of DB calls, and do an update only when[/color]
        a[color=blue]
        > change is detected.
        >
        > If I have the code the following way,
        >
        > if (this.HIRE_DT.T ext.ToString(). Trim() != ""){
        > oRow["HIRE_DT"] = Convert.ToDatei
        > Time(this.HIRE_ DT.Text.ToStrin g().Trim());
        > }else{
        > oRow["HIRE_DT"] = DBNull.Value;
        > }
        >
        > Assuming the date in the HIRE_DT textbox was null initially, since i am
        > setting an explicit DBNull.Value here again, even though the user doesn't[/color]
        do[color=blue]
        > anything in the UI, the program will set a DBNull.Value and the dataset
        > detects a change
        >
        > ie.
        > ds.HasChanges() will detect a change, and DataViewRowStat e.ModifiedCurre nt
        > will do an extra DB call.
        >
        > Thank you,
        > Yog
        >
        > "Marina" <someone@nospam .com> wrote in message
        > news:%231nnACJ2 EHA.3820@TK2MSF TNGP11.phx.gbl. ..[color=green]
        > > What are you asking exactly? Howe to set a date field in a dataset to[/color]
        > null?[color=green]
        > >
        > > oRow["HIRE_DT"] = DBNull.Value;
        > >
        > > "Yog" <shiva_jm@hotma il.com> wrote in message
        > > news:%23MqI4%23 I2EHA.3500@TK2M SFTNGP09.phx.gb l...[color=darkred]
        > > > I am trying to update a date column in dataset from a textbox.
        > > >
        > > > When a date is changed in textbox, the dataset should reflect this,
        > > > similarly when the textbox is cleared to null the dataset should[/color][/color][/color]
        reflect[color=blue][color=green][color=darkred]
        > > > this. This is since i use the "DataViewRowSta te.ModifiedCurr ent" later[/color][/color]
        > to[color=green][color=darkred]
        > > > detect the changes for update.
        > > >
        > > > How do we acheive this?.
        > > >
        > > > Currently since i am ignoring nulls, i miss the null condition.
        > > > if (this.HIRE_DT.T ext.ToString(). Trim() != ""){
        > > >
        > > > oRow["HIRE_DT"] =
        > > > Convert.ToDateT ime(this.HIRE_D T.Text.ToString ().Trim());
        > > >
        > > > }
        > > >
        > > >
        > > >
        > > > Thank you,
        > > >
        > > > Yog
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...