DateTime data insert to sql server

Hi…

Using if condition
var ==System.Nullable<System.DateTime>

Assign Closed_Date =If( String.IsNullOrEmpty(Exl_Closed_Date.ToString),System.Convert.ToDateTime(DBNull.Value), DateValue(Exl_Closed_Date))

Error

Assign: Object cannot be cast from DBNull to other types.

Thanks
Shyam

Hi @Shyam_Pragash

Dbnull cannot be converted …try assigning dbnull directly if it doesnot work then you have to assign a dummy date like 01/01/1900 00:00 so that you know it is a dummy date

Cheers

Hi @Anil_G

Null value is allowed…

i cant write dummy value in the DB.

Thanks
Shyam

Hi @Shyam_Pragash

Can you try like this

If( String.IsNullOrEmpty(Exl_Closed_Date.ToString),DBNull.Value, DateValue(Exl_Closed_Date))

By giving only DBNull.Value

Cheers

Hi @Anil_G

As per ur advice.

image

i am getting complier error

image

whether i have to change the varable type or not ?

used variable type:

Thanks
shyam

Hi @Shyam_Pragash

Please change the datataype of the variable to object from datetime and check that shpuld solve it

Cheers

Hi @Anil_G

Still i am facing issue…

image

Thanks
Shyam

Hi @Shyam_Pragash

I still see date_Db as datetime type. Can you change that to object please

Cheers

Hi @Anil_G

Same issue.

image

Cheers

Thanks
Shyam

Hi @Shyam_Pragash

Instead of using if like this …can you drag a if activity and assign both in two conditions please

This way you wpuld be able to assign for the old nullable datetime type also i beleive

Or try new object(DBNull.Value) repeat same for the date value as well

Cheers

Hi @Anil_G

I will check and Update u…

Thanks
Shyam

1 Like

Hi @Anil_G

Unable to insert the data to sql server…

Thanks
Shaym

Hi @Shyam_Pragash

Is it because we are using object or because of Null?

If it is because we changed to object now we can change to Nullable datatetime I believe as we are using a IF activity

If it is because of Null try to Give Nothing

can you show the error

cheers

1 Like

Hi @Anil_G

Thanks :). i can able to insert the data in sql server…

but i have on issue… wrong data inserted to sql server…

Time is missing…

Thanks
Shyam

1 Like

HI @Shyam_Pragash

Please use DateTimeValue(Variable) instead of DateValue

Happy Automation

cheers

DateTimeValue function not available… can u tell me how to add ?

Thanks
Shyam

Hi @Shyam_Pragash

Try timevalue or a combination of datevalue and timevalue

cheers

Hi @Anil_G @RajKumar_DC

Thanks All :slight_smile: :+1:

Finally we found the soluation to import Null data with specificed variable types in sql server.

If ( String.IsNullOrEmpty(Exl_Created_At), New Nullable(Of Date), System.Convert.ToDateTime(Exl_Created_At))

Variable Type : Nullable.System.Datetime

Thanks
Shyam

1 Like

The simplest method to insert the current date and time in MySQL is to use the now() function. Once you call the function, it returns the current date and time in the system’s configured time zone as a string. The value returned from the now() function is YYYY-MM-DD for the date and HH-MM-SS-UU for the time record.

Regards,
Will

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.