Estaba probando las funciones de Raul y encontré un error.
En la funcion UpdateTabla
'cargo un valor tipo string
campos(0) = CampoValue("Producto", "PEPE")
'esta funcion carga el valor, y GetRowValue formatea el dato, en este caso un string, entonces los encierra entre ' '
Public Function CampoValue(Nombre As String, Valor, Optional tipo As CampoTipo = tipoString) As campo
With CampoValue
.Nombre = Nombre
.tipo = tipo
.Valor = GetRowValue(Valor, tipo)
End With
End Function
Public Function GetRowValue(Valor, tipo As CampoTipo) As String
Select Case tipo
Case CampoTipo.tipoDate
Dim d As Date, limit As String, sep As String
d = Valor
Select Case dbEngine
Case dbAccess
limit = "#": sep = "/"
Case dbMySQL
limit = "'": sep = "-"
End Select
GetRowValue = limit & Year(d) & sep & Month(d) & sep & Day(d) & limit
Case CampoTipo.tipoNumero
GetRowValue = CLng(Valor)
Case CampoTipo.tipoString
GetRowValue = "'" & Valor & "'"
Case CampoTipo.tipoBoolean
If CBool(Valor) Then
GetRowValue = "1"
Else
GetRowValue = "0"
End If
Case CampoTipo.tipodouble
GetRowValue = Replace$(CDbl(Valor), ",", ".")
End Select
End Function
'ahora campos(0).valor = 'PEPE'
'y cuando llamamos a UPDATETABLA, vuelve a formatear el valor
Public Function UpdateTabla(ByVal Tabla As String, campos() As campo, sWhere As String, cnn As ADODB.Connection) As Boolean
Dim sql As cStringBuilder
Dim i As Integer, j As Integer
Set sql = New cStringBuilder
Call sql.Append("UPDATE " & Tabla & " SET ")
j = UBound(campos)
For i = 0 To j
Call sql.Append(campos(i).Nombre & "=")
'aca cuando se concatena, se vuelve a formatear el campo
'agregar un ''PEPE'' (es decir doble comilla simple, a ambos lados)
Call sql.Append(GetRowValue(campos(i).Valor, campos(i).tipo))
'creo que lo correcto seria:
Call sql.Append(campos(i).valor)
If Not i = j Then
Call sql.Append(",")
End If
Next
Call sql.Append(" WHERE " & sWhere & ";")
Call cnn.Execute(sql.Value, i)
Debug.Print sql.Value, "Rows Affected: " & i
UpdateTabla = i
Set sql = Nothing
End Function