Hi,

I have 2 projects, the business entity, there I have all the classes mapped from the database and the web project where I fill those business entity classes. Then, I need to store in a DB. I have the globalization set in the web.config on the web project. (VS2008, NET 3.5, SQL 2005)

My problem is when I have an instance of the BE class, and I have a date attribute on it, the value entered is not formatted according the globalization in the web.config, and obviously when I pass to the class to store in the DB it fails due to date format.

I think is missing some configuration... but I googled for it and no luck.

There you have part of my coding:

Business Entity:

Public Class Categoria
    Inherits AuditBaseClass

    Private _categ_id As String
    Private _categ_descripcion As String
    Private _categ_tipo_item As Integer
    Private _categ_parent As String
    Private _categ_estado_registro As Char
    Private _creado_usuario As String
    Private _creado_fecha As DateTime
    Private _modificado_usuario As String
    Private _modificado_fecha As DateTime

[...]

    Public Property creado_fecha() As DateTime
        Get
            Return Me._ creado_fecha
        End Get
        Set(ByVal value As DateTime)
            Me._ creado_fecha = value
        End Set
    End Property

[...]

End Class

Web Project (WebSite)

Private Sub guardar_datos()

        Dim oCategoriaWCF As New definiciones.DefinicionesClient    '<--- Class to store in DB
        Dim oCategoriaBE As New BE.Categoria                         '<--- Object with the Date Attribute

        Dim result As Integer = -1

        oCategoriaBE.id = CInt(Session.Item("data.id"))
        oCategoriaBE.categ_descripcion = Me.txtDescripcion.Text.Trim
        oCategoriaBE.categ_tipo_item = Me.ddlTipoItem.SelectedValue
        oCategoriaBE.categ_parent = Me.ddlParent.SelectedValue.Trim
        If oCategoriaBE.id = Nothing Or oCategoriaBE.id = 0 Then
            oCategoriaBE.creado_usuario = Session.Item("gen.user_name")
            oCategoriaBE.creado_fecha = Now()                     '<--- Now() method returns the incorrect date format and also the value stored 
        Else
            oCategoriaBE.modificado_usuario = Session.Item("gen.user_name")
            oCategoriaBE.modificado_fecha = Now()                 '<--- Now() method returns the incorrect date format and also the value stored 
        End If

        Try
            result = oCategoriaWCF.GuardarCategoria(oCategoriaBE)        '<---- this method fails when it tries to store in the DB
        Catch ex As Exception
            result = -2
        Finally
            oCategoriaWCF.Close()
        End Try

        If result > 0 Then
            Me.lblResponse.Text = "Los datos fueron guardados satisfactoriamente"
            carga_datos()
            limpiar_controles()
        Else
            Me.lblResponse.Text = "Hubo un error al guardar los datos"
        End If

        oCategoriaWCF = Nothing
    End Sub

web.config

<system.web>
    <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" uiCulture="es-PE" culture="es-PE" />
</system.web>

Thanks!

I never found a solution to the exact same problem you're having. I had a BE project that did transaction posting to a payment gateway and I tested it on a winform application and it worked perfectly .. then when I used it from a web application assembly it failed and I spent hours to figure out that the web apps and desktop apps format differently.

I never found a solution using localization. I began explicitly calling the .ToString() with the desired DateFormat options. The number of decimal places, separator, etc also varied between the desktop and web apps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.