This is a migrated thread and some comments may be shown as answers.

[Solved] pass in null, but save as '01/01/1900'

4 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Esperanza Ramos
Top achievements
Rank 1
Esperanza Ramos asked on 07 May 2008, 01:30 PM
Hi, All:

I am using RadGrid and trying to implement "Update All" feature.

I explicitly pass in null, but save as '01/01/1900/ to database table.

protected void rgJobInv_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "UpdateAll")
{
foreach (Telerik.Web.UI.GridEditableItem editedItem in rgJobInv.EditItems)
{
Hashtable newValues = new Hashtable();
e.Item.OwnerTableView.RetrieveNullAsDBNull =
true;
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

sdsUpdateAll.UpdateCommand =

string.Format("update tblJobInventory set District='{0}', ......" +
", Shipped = '{15}' " +
", Billed = '{16}' ....."

, newValues[

"District"].....
,
null /*newValues["Shipped"]*/
, null /* newValues["Billed"]*/

In database table, "Shipped" and "Billed" is smalldatetime type.
I pass in null, but both "Shipped" and Billed are saved as '01/01/1900'.
even when I pass newValues["Shipped"], which is null, but still it was saved
as '01/01/1900'.

Please give some ideas.
thanks.

Stanley Huang


4 Answers, 1 is accepted

Sort by
0
Esperanza Ramos
Top achievements
Rank 1
answered on 09 May 2008, 12:15 PM
Hi, All:

Please, can some one help with this question.

thanks.

Stanley
0
Rosen
Telerik team
answered on 10 May 2008, 07:27 AM
Hello Stanley Huang,

There are several way to save null in DB's datetime field instead of the default value, depending on how you update the data.

If you are using ADO.NET classes such as IDbCommand you can pass to the update parameter's SqlDateTime.Null value.

Or if you are using SqlDataSource you can set datetime parameter's ConvertEmptyStringToNull property to true and pass string.Empty as value.

Greetings,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Esperanza Ramos
Top achievements
Rank 1
answered on 12 May 2008, 01:38 PM
Hi, Telerik Team:

Thank you.  I am using VS 2005.  There is no ConvertEmptyStringToNull property in SqlDataSource, at least I did not find it.

In this case, is there an alternative solution, for VS 2005?

Thanks.

Stanley Huang
0
Rosen
Telerik team
answered on 14 May 2008, 03:16 PM
Hello Stanley Huang,

As stated earlier ConvertEmptyStringToNull is a property of parameter object and not of the DataSource itself. I have attached a simple project demonstrating described scenario. Please give it a try and see if it helps or am I missing something.

All the best,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Esperanza Ramos
Top achievements
Rank 1
Answers by
Esperanza Ramos
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or