If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > JavaScript with SQL NVARCHAR Datatype

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-11-04, 23:40
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Wink JavaScript with SQL NVARCHAR Datatype

Hello,

I am new to this forum. I have a question and hope someone might be able to help me. I did search this forum but can not find any solution. So here is my problem.

I have a column call "Notes" that defined in the SQL Server 2000 database table as a nvarchar[2000] datatype. The "Notes" column contains both English and Russian text. Here goes:

Use VBscript to retrieve "Notes" data from SQL database
<%
dim notes_buffer

<!-- retrieve from database and assign to notes_buffer -->

notes_buffer = recordSet.GetString
response.write(" Notes: " & notes_buffer)
%>

I got the data from the SQL database and displayed it to the WebPage without any problem.

Then try to use JavaScript functions, so I can parse and work on the data

<script type="text/JavaScript">

var buffer = <%=notes_buffer%> ; // not working
or
var buffer = '<%=notes_buffer%>'; // not working

document.write(" BUF = " + buffer);
</script>

I tested the above statement with a "char" and "int" datatype no problem, but it is not working with a "nvarchar" datatype data.
Is anyone out there know the soultion? I'm really appreciated some help here thanks.

Rob
Reply With Quote
  #2 (permalink)  
Old 02-12-04, 00:53
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
try

<script type="text/JavaScript">

var buffer = <%=cstr(notes_buffer)%> ; // not working
or
var buffer = '<%=cstr(notes_buffer)%>'; // not working

document.write(" BUF = " + buffer);
</script>

or perhaps even escaping it.... if you don't escape it then when your text has a ' in it you will start running into errors.
Reply With Quote
  #3 (permalink)  
Old 02-12-04, 12:32
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Thanks for the reply... I did try it, but it did not work... BTW, what is 'cstr'? I did notice that when I view the source contents (without or with cstr ), the variable buffer did pick up all the (English and Russian) text. Don't know why it can't display to the WebPage, and why it did not execut the <script> section.

Rob

Quote:
Originally posted by rokslide
try

<script type="text/JavaScript">

var buffer = <%=cstr(notes_buffer)%> ; // not working
or
var buffer = '<%=cstr(notes_buffer)%>'; // not working

document.write(" BUF = " + buffer);
</script>

or perhaps even escaping it.... if you don't escape it then when your text has a ' in it you will start running into errors.
Reply With Quote
  #4 (permalink)  
Old 02-12-04, 12:38
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
What is that "notes_buffer = recordSet.GetString" ?
Reply With Quote
  #5 (permalink)  
Old 02-12-04, 15:54
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
notes_buffer contains the retrieved data from database.

Quote:
Originally posted by gyuan
What is that "notes_buffer = recordSet.GetString" ?
Reply With Quote
  #6 (permalink)  
Old 02-12-04, 16:06
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
In JavaScript, when you pass a string to the variable, you need "". Try this:

var buffer = "<%=notes_buffer%>";
Reply With Quote
  #7 (permalink)  
Old 02-12-04, 17:08
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Hi gyuan,

Acutally, that's not true you can use either " or '. Some browsers have problems with " though.

The cstr converts the variable to a string. It theory this happens implicitly when you concatentate strings (you first example that works).

It is probably happening implicitly in the second example as well be the cstr will make it explicit.

What is the JavaScript that is actually generated?

var buffer = ''; ??

or is it something else? Can you post the complete file that doesn't work? Perhaps it isn't this line that is the problem...?
Reply With Quote
  #8 (permalink)  
Old 02-12-04, 21:00
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Hello again,

I finally figured out why today, cause there were some Line Feed (LF) and Carriage Return (CR) in the data itself (document contains about 500 lines of english and russian text). I used VBCRLF to replace LF+CR to a "&" character and it worked fine now. Somehow the JavaScript variables do not like the LF or CR in the "string". So, the case is closed now. Thanks for paying attention to my problems:P

My next assignments would be trying to PRINT (not window.print) a nicely formmated webpage. I'll really appreciated the anyone out there knows some of the tricks, or ASP/JavaScript examples or poits out threads that discuss this subject.

Rob




Quote:
Originally posted by rokslide
Hi gyuan,

Acutally, that's not true you can use either " or '. Some browsers have problems with " though.

The cstr converts the variable to a string. It theory this happens implicitly when you concatentate strings (you first example that works).

It is probably happening implicitly in the second example as well be the cstr will make it explicit.

What is the JavaScript that is actually generated?

var buffer = ''; ??

or is it something else? Can you post the complete file that doesn't work? Perhaps it isn't this line that is the problem...?
Reply With Quote
  #9 (permalink)  
Old 02-12-04, 21:45
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
heheh thought it might be something like that...

So you are replace your carriage returns with /n (or is it \n, I can never remember).
Reply With Quote
  #10 (permalink)  
Old 02-12-04, 22:58
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
Quote:
Originally posted by rokslide
Acutally, that's not true you can use either " or '. Some browsers have problems with " though.
I'm not sure if double quotaion marks work with all kind of the broswers, but it works in my application.
Reply With Quote
  #11 (permalink)  
Old 02-12-04, 23:04
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
heheheh that is the important thing right?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On