cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid date Value

Former Member
0 Kudos

Dear members,

In a form, I have a textfield to enter date and it is linked with Userdatasource - Date.

When I try to retrieve data from the table to show in the form, I got an exception ' Invalid date'. Can anyone help to resolve this problem?

objForm.DataSources.UserDataSources.Add("U6", SAPbouiCOM.BoDataType.dt_DATE

objText.DataBind.SetBound(True, "", "U6"))

If Not objRS.EoF Then

objForm.Items.Item("B4").Specific.string = objRS.Fields.Item("U_BatchnumLength").Value

Dim strdate As Date = objAddOn.objGenFunc.GetDateTimeValue(objRS.Fields.Item("U_FirstInsBatchNum").Value)

objForm.Items.Item("B6").Specific.value = strdate

objForm.Items.Item("B8").Specific.value = objAddOn.objGenFunc.GetDateTimeValue(CStr(objRS.Fields.Item("U_FreshBatchNumber").Value))

objForm.Items.Item("B10").Specific.string = CStr(objRS.Fields.Item("U_Separator").Value)

End if

Thanks and Regards,

Tamil

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Dear Tamil

You wrote

-


Dear members,

In a form, I have a textfield to enter date and it is linked with Userdatasource - Date.

When I try to retrieve data from the table to show in the form, I got an exception ' Invalid date'. Can anyone help to resolve this problem?


objForm.DataSources.UserDataSources.Add("U6", SAPbouiCOM.BoDataType.dt_DATE
objText.DataBind.SetBound(True, "", "U6"))

If Not objRS.EoF Then
  objForm.Items.Item("B4").Specific.string = objRS.Fields.Item("U_BatchnumLength").Value

  Dim strdate As Date = objAddOn.objGenFunc.GetDateTimeValue(objRS.Fields.Item("U_FirstInsBatchNum").Value)
  objForm.Items.Item("B6").Specific.value = strdate
  objForm.Items.Item("B8").Specific.value = objAddOn.objGenFunc.GetDateTimeValue( _
                                             CStr(objRS.Fields.Item("U_FreshBatchNumber").Value))
  objForm.Items.Item("B10").Specific.string = CStr(objRS.Fields.Item("U_Separator").Value)
End if

Thanks and Regards,

Tamil

Hi Tamil

-


I think I can help you to solve the problem.

To try this you can use some of SAP B1 SDK Samples.

I'm used COM UI\VB.NET\17.ChooseFromList and at end of CreateForm() subroutine I have inserted this code.


oForm.Width = 400
oForm.Height = 300

Try
  ''// Adding Init Date field
  oEdit = Nothing
  oItem = Nothing
  'oForm.DataSources.UserDataSources.Add("uIniDate", SAPbouiCOM.BoDataType.dt_DATE)
  oForm.DataSources.UserDataSources.Add("U6", SAPbouiCOM.BoDataType.dt_DATE)
  ' +++++++++++++++++++++++++++++++++++++++++++++++++++++
  ' Adding a text box
  'oItem = oForm.Items.Add("eIniDate", SAPbouiCOM.BoFormItemTypes.it_EDIT)
  oItem = oForm.Items.Add("B6", SAPbouiCOM.BoFormItemTypes.it_EDIT)
  oItem.Left = 120
  oItem.Top = 120
  oItem.Width = 80
  oItem.Height = 20
  oItem.Enabled = True
  oItem.Description = "Init Date"
  ' +++++++++++++++++++++++++++++++++++++++++++++++++++++
  oEdit = oItem.Specific
  'oEdit.DataBind.SetBound(True, "", "uIniDate")
  oEdit.DataBind.SetBound(True, "", "U6")
  ' +++++++++++++++++++++++++++++++++++++++++++++++++++++
  Dim dtIni As Date = DateTime.Now
  oEdit.Value = _
      Microsoft.VisualBasic.Strings.Format(dtIni.Year, "0000") & _
      Microsoft.VisualBasic.Strings.Format(dtIni.Month, "00") & _
      Microsoft.VisualBasic.Strings.Format(dtIni.Day, "00")
  ' +++++++++++++++++++++++++++++++++++++++++++++++++++++
  oEdit = Nothing
Catch ex As Exception
  Dim s As String = ex.Message
Finally
  oEdit = Nothing
  oItem = Nothing
End Try

oForm.Visible = True

HTH

BR

Sierdna S.

Former Member
0 Kudos

Dear all,

I have closed this issue by binding to the sql table fields. and I set oEdit.string instead of oEdit.value.

Thank you for all your reply.

Regards,

Tamil

Former Member
0 Kudos

Hi Tamil,

I would never use the oEditText.String-Property because it's format depends on the user settings. You would always need to check what the actual display B1-user-setting for date is and then format the date accordingly. But this complicates things too much.

Instead I would use...

1. UserDataSource.ValueEx

Independent from display, language or whatever settings you can set this with a date (as a string!) in format "20080918"

Since a RecordSet gives a real .NET-DateTime Value in case of a date-column you need a function

DateToYYYYMMDDString (ByVal myDate as system.datetime) As String

to cover this (should be no problem ;-).

For Double-Values (EditText is bound to UserDataSourc of type price, quantity...) you must always set a string in format "2349.45" (decimal seperator is always a dot also when the user has defined a "#" as dec.-sep!

2. EditText.Value

The same as above!

You may also have a look at my answer here (same topic):

Former Member
0 Kudos

Hi,

After getting the date frm the database and setting the value in the edit text change the formate of the date, Cause when u get the date frm SQL u get it along with the time. U can use the folling to format the date.

date.ToString("mm/dd/yyyy")

Hope it helps,

Vasu Natari.

Former Member
0 Kudos

Hi Vasu,

As I have bind the text field with date value, I could not set String value. hope you understand my problem.

Thanks and regards,

Tamil

Former Member
0 Kudos

Then try something as follows,

Convert.ToDateTime(date.ToString("mm/dd/yyyy"))

Hope it helps,

Vasu Natari.