conversion failed when converting date and/or time from character string, usando SQL Server Azure.

ELIRDFUL 185 Reputation points
2024-07-01T13:46:02.71+00:00

Hello everyone

I have the following code:

 Try


            Dim Fechini As Date
            Dim Fechfin As Date

            Fechini = Format(DateTimePickerDesde.Value, "dd/MM/yyyy")
            Fechfin = Format(DateTimePickerHasta.Value, "dd/MM/yyyy")

            

            If CboBuscarConsultaPrestamo.Text = "INGRESOS ANULADOS" Then

                Using cn As New SqlConnection(cadenaConexion)
                    Dim consultaSQL As String = " Select INGRESO.NumeroReciboIngreso as Codigo_Ingresos,INGRESO.FechaRegistro as fecha_registro,INGRESO.CodigoCliente as Codigo_cliente, CLI.nom_cli as Nombre, CLI.apell_cli as Apellido,INGRESO.TotalesBalanceFactura as Totales_BalanceFactura, INGRESO.TotalesAbono as Totales_Abono from TblaRecibosIngresosss INGRESO  LEFT JOIN tbla_clientes CLI ON INGRESO.CodigoCliente=CLI.codigo_cliente where  INGRESO.FechaRegistro BETWEEN ('" & Fechini & "') AND ('" & Fechfin & "') and  INGRESO.estatus = " & "'CANCELADA'" & " "

                    Dim adap As New SqlDataAdapter(consultaSQL, cn)
                    Dim dt As New DataTable()

                    adap.Fill(dt)

                    DgvConsultaCobranza.DataSource = dt
                End Using
            End If


            If Val(TxtTotalPrestamoConsulta.Text) = 0 Then

                MsgBox("Datos no encontrado")
                TxtTotalPrestamoConsulta.Focus()
            End If
        Catch ex As Exception
            MsgBox(ex.Message.ToString())

        End Try

When I execute the query in SQL Server locally it doesn't give me errors, everything is fine, excellent.

But when I run the query using SQL Server Azure, I get the following error.

User's image

I count on your help.....

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,642 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 28,076 Reputation points Microsoft Vendor
    2024-07-02T01:42:13.3533333+00:00

    Hi @ELIRDFUL ,

    Try using ToString("yyyy-MM-dd") to format the dates.

        Fechini = DateTimePickerDesde.Value.ToString("yyyy-MM-dd")
        Fechfin = DateTimePickerHasta.Value.ToString("yyyy-MM-dd")
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful