Solved

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

Posted on 2016-11-04
10
30 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
  • 6
  • 2
10 Comments
 
LVL 12

Expert Comment

by:Jeff Darling
Comment Utility
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
Comment Utility
odbc sql server driver Operand type clash: nvarchar is incompatible with image
0
 

Author Comment

by:BFanguy
Comment Utility
i am guessing i have to convert it to unicode double byte before i try to insert???
0
 

Author Comment

by:BFanguy
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 250 total points
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now