[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need to insert text into a IMAGE field as Double Byte from vbscript into SQL table

Posted on 2016-11-04
10
Medium Priority
?
105 Views
Last Modified: 2016-11-09
I had a vbscript (macro) that inserted records into a IMAGE field in a SQL Server database,

              pmspec = pmspec & vbCrLf & "Reason for Obsoletion: " & result & " By: " & Network_User & " - " & Now()
              Set db = CreateObject("ADODB.Connection")
              db.Open SCONNUPD
              SET RSu = CREATEOBJECT("ADODB.RECORDSET")
              SSQLUPD = "INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('" & ID & "'" & chr(44) & "'D'" & chr(44) & "'" & pmspec & "'" & chr(44) & Len(pmspec) & ")"
              Set RSu = db.Execute(SSQLUPD)

Open in new window

Now our ERP vendor has upgraded all of their fields to DoubleByte (including the BITS (IMAGE) field above.

I can not figure out how to write the insert now to convert my text to DoubleByte.

I do know that I will need to change my Len(pmspec) to LenB(pmspec)  (the table stores the length in bytes of the field into BITS_LENGTH)

Any help is greatly appreciated.
0
Comment
Question by:BFanguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
10 Comments
 
LVL 13

Expert Comment

by:Jeff Darling
ID: 41874722
put in N in front of the BITS value.

something like this:

              pmspec = pmspec & vbCrLf & "Reason for Obsoletion: " & result & " By: " & Network_User & " - " & Now()
              Set db = CreateObject("ADODB.Connection")
              db.Open SCONNUPD
              SET RSu = CREATEOBJECT("ADODB.RECORDSET")
              SSQLUPD = "INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('" & ID & "'" & chr(44) & "'D'" & chr(44) & " N'" & pmspec & "'" & chr(44) & Len(pmspec) & ")"
              Set RSu = db.Execute(SSQLUPD)

Open in new window

0
 

Author Comment

by:BFanguy
ID: 41874737
odbc sql server driver Operand type clash: nvarchar is incompatible with image
0
 

Author Comment

by:BFanguy
ID: 41874738
i am guessing i have to convert it to unicode double byte before i try to insert???
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:BFanguy
ID: 41874745
tried from ssms:

INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('BM305-0295800-1600-1','D', N'test', Len('test')*2)

Msg 206, Level 16, State 2, Line 1
Operand type clash: nvarchar is incompatible with image
0
 
LVL 13

Assisted Solution

by:Jeff Darling
Jeff Darling earned 1000 total points
ID: 41874850
ok, data type in the database is image.

https://msdn.microsoft.com/en-us/library/ms187993.aspx

Then do a conversion cast as image

https://msdn.microsoft.com/en-us/library/ms191530.aspx

INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('BM305-0295800-1600-1','D', cast('test' as image), Len('test')*2)

Open in new window

0
 

Author Comment

by:BFanguy
ID: 41877028
thanks, tried your statement, the app show chinese characters.

tried
INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('BM305-0295800-1600-1','D', cast( N'test' as image), Len('test')*2)

Open in new window


Explicit conversion from data type nvarchar to image is not allowed.
0
 

Accepted Solution

by:
BFanguy earned 1000 total points
ID: 41877040
Tried this and it worked.  thanks.

INSERT INTO PART_MFG_BINARY ([PART_ID],[TYPE],[BITS],[BITS_LENGTH]) VALUES ('BM305-0295800-1600-1','D',CAST(CAST('test' AS NVARCHAR(MAX)) AS VARBINARY(MAX)), Len('test') * 2 )

Open in new window

0
 

Author Comment

by:BFanguy
ID: 41877455
Jeff, sorry i thought i could give you the points even if i picked best solution.  trying to figure out what i have to do to give you the points
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question