Simple Date Question

  • Thread starter Thread starter Yog
  • Start date Start date
Y

Yog

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 "DataViewRowState.ModifiedCurrent" 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.Text.ToString().Trim() != ""){

oRow["HIRE_DT"] =
Convert.ToDateTime(this.HIRE_DT.Text.ToString().Trim());

}



Thank you,

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

oRow["HIRE_DT"] = DBNull.Value;
 
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.Text.ToString().Trim() != ""){
oRow["HIRE_DT"] = Convert.ToDatei
Time(this.HIRE_DT.Text.ToString().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 DataViewRowState.ModifiedCurrent
will do an extra DB call.

Thank you,
Yog

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

oRow["HIRE_DT"] = DBNull.Value;

Yog said:
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 "DataViewRowState.ModifiedCurrent" 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.Text.ToString().Trim() != ""){

oRow["HIRE_DT"] =
Convert.ToDateTime(this.HIRE_DT.Text.ToString().Trim());

}



Thank you,

Yog
 
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 said:
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.Text.ToString().Trim() != ""){
oRow["HIRE_DT"] = Convert.ToDatei
Time(this.HIRE_DT.Text.ToString().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 DataViewRowState.ModifiedCurrent
will do an extra DB call.

Thank you,
Yog

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

oRow["HIRE_DT"] = DBNull.Value;

Yog said:
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 "DataViewRowState.ModifiedCurrent" 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.Text.ToString().Trim() != ""){

oRow["HIRE_DT"] =
Convert.ToDateTime(this.HIRE_DT.Text.ToString().Trim());

}



Thank you,

Yog
 
Back
Top