Añadir campos memos grandes en vbscript

Posted on mayo 7, 2014

0



Grabar usando parametros

 oRs = conexion.Execute(“UpdateProgMtto(” & cparam & “)”, nReg, 4)        
    notas = UCASE(Trim(Request.Form(“notas”)))
    if len(notas) > 0 then 
        set oCmd = server.CREATEOBJECT(“ADODB.Command”)
        strMsgText = notas
        oCmd.ActiveConnection = conexion
        strSQL = “update progmtto set notas = ? Where uid = ” & progid
        oCmd.CommandText=strSQL
        set parm1=oCmd.CreateParameter(“notas”,200,1)
        parm1.size=LEN(strMsgText)
        parm1.Value=strMsgText
        oCmd.Parameters.Append(parm1)
        oCMD.Execute
    else 
        set UPProg = conexion.execute(“update progmtto set notas = ” Where uid = ” & progid)
        set UPProg = nothing
    end if    

Grabar usando parámetros, texto tomado de grupo de noticias, Sr. Victor:

dim sqlCommand 
  dim adVarChar
  dim adLongVarChar
  dim adParamInput
  sqlCommand = “INSERT INTO Customers (custId, custName, custStat, custNotes) VALUES (?, ?, ?, ?)”
  adVarChar = 200
  adLongVarChar = 201
  adParamInput = 1
  dim custId
  dim custNotes
  custId = “9999”
  custNotes = string(1024,”x”)

Set conn = CREATEOBJECT(“ADODB.Connection”)

  conn.Open(“Provider=VFPOLEDB.1;Data   Source=e:/pvf/sos/customers.dbf;Mode=ReadWrite”) 
  Set cmd = CreateObject(“ADODB.Command”)
  cmd.activeConnection = conn
  cmd.commandText = sqlCommand
  cmd.parameters.append(cmd.createParameter(“”, adVarChar, adParamInput, 255, custId))
  cmd.parameters.append(cmd.createParameter(“”, adVarChar, adParamInput, 255, “Victor Espina”))
  cmd.parameters.append(cmd.createParameter(“”, adVarChar, adParamInput, 255, “Active”))
  cmd.parameters.append(cmd.createParameter(“”, adLongVarChar, adParamInput,len(custNotes), custNotes))
  cmd.execute()
  conn.Close()

———–

Convertir la cadena en base64 y que mantenga los acentos y las Ñ/ñ

Function FasterBase64Encode(sText)

Dim oXML, oNode

Set oXML = CreateObject(“Msxml2.DOMDocument.3.0”)
Set oNode = oXML.CreateElement(“base64”)
oNode.dataType = “bin.base64”

oNode.nodeTypedValue =Stream_StringToBinary(sText)
‘ Base64Encode = oNode.text
FasterBase64Encode = oNode.text
Set oNode = Nothing
Set oXML = Nothing
End Function

Function Base64Decode(ByVal vCode)
Dim oXML, oNode

Set oXML = CreateObject(“Msxml2.DOMDocument.3.0”)
Set oNode = oXML.CreateElement(“base64”)
oNode.dataType = “bin.base64”
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
Set oXML = Nothing
End Function

‘Stream_StringToBinary Function
‘2003 Antonin Foller, http://www.motobit.com
‘Text – string parameter To convert To binary data
Function Stream_StringToBinary(Text)
Const adTypeText = 2
Const adTypeBinary = 1

‘Create Stream object
Dim BinaryStream ‘As New Stream
Set BinaryStream = CreateObject(“ADODB.Stream”)

‘Specify stream type – we want To save text/string data.
BinaryStream.Type = adTypeText

‘Specify charset For the source text (unicode) data.
‘ BinaryStream.CharSet = “us-ascii”
BinaryStream.CharSet = “windows-1252”
‘Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text

‘Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary

‘Ignore first two bytes – sign of
BinaryStream.Position = 0

‘Open the stream And get binary data from the object
Stream_StringToBinary = BinaryStream.Read

Set BinaryStream = Nothing
End Function

‘Stream_BinaryToString Function
‘2003 Antonin Foller, http://www.motobit.com
‘Binary – VT_UI1 | VT_ARRAY data To convert To a string
Function Stream_BinaryToString(Binary)
Const adTypeText = 2
Const adTypeBinary = 1

‘Create Stream object
Dim BinaryStream ‘As New Stream
Set BinaryStream = CreateObject(“ADODB.Stream”)

‘Specify stream type – we want To save binary data.
BinaryStream.Type = adTypeBinary

‘Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write Binary

‘Change stream type To text/string
BinaryStream.Position = 0
BinaryStream.Type = adTypeText

‘Specify charset For the output text (unicode) data.
‘ BinaryStream.CharSet = “us-ascii”
BinaryStream.CharSet = “windows-1252”

‘Open the stream And get text/string data from the object
Stream_BinaryToString = BinaryStream.ReadText
Set BinaryStream = Nothing
End Function

 

Para no perder el español, hay que usar:

BinaryStream.CharSet = “windows-1252”

 

Posted in: VBScript