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 > Type mismatch error on FileSystemObject method

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-13-04, 14:33
joshilat joshilat is offline
Registered User
 
Join Date: May 2004
Posts: 4
Type mismatch error on FileSystemObject method

Hi Experts,

I'm trying to read data from a sql table, and writing to a flat file(CSV file), for which I'm using Filesystem object. Getting error while writing data to the file on WriteLine method of the FSO object. But some data is being written to the file. But every time I get the error, different number of records were being written to the flat file. Not getting the error on same record every time. Any help pelase....

My code is

'*************************************
For j = 0 To Rs.RecordCount-1
For Each Field In Rs.Fields
If Data <> "" Then
Data = Data & "%" & Field.Value
Else
Data = Field.Value
End If
Next

objTxtStream.WriteLine Data
Data = ""
Rs.MoveNext
Next
'************************************


Error message is

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'objTxtStream.WriteLine'
/Survey_FilesDownload.asp, line 119

Reply With Quote
  #2 (permalink)  
Old 05-13-04, 15:09
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
It depends on your datatypes of your columns and real data. What are the datatypes? In your data, do you allow NULL value or some strings with some specific characters?
Reply With Quote
  #3 (permalink)  
Old 05-13-04, 15:38
joshilat joshilat is offline
Registered User
 
Join Date: May 2004
Posts: 4
Yes we allow NULL values in db. Do you think of any special characters can cause the problem? If so what are they and what should I do?
Reply With Quote
  #4 (permalink)  
Old 05-13-04, 16:16
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
How much disk space do you have available on that drive?
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #5 (permalink)  
Old 05-14-04, 14:30
joshilat joshilat is offline
Registered User
 
Join Date: May 2004
Posts: 4
I was able to fix it. Actually it is a data error. When I try to write NULL line to the flat file, I got that error.
Reply With Quote
  #6 (permalink)  
Old 05-14-04, 14:43
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Right.. NULL is not a string, and WriteLine is expecting a string.
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #7 (permalink)  
Old 05-15-04, 15:02
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Hello,

How about handle data with "nvarchar" datatype in database? I tried to create/save a CSV file with mixed datatype (ex. int, char, varchar and nvarchar). I keep getting "invalid procedures and arguments" when I have the following code:

strline = " "
Do until rs.EOF
for each x in rs.Fields
strline = strline & x.value & chr(9)
next
myFile.writeline strline // this is where error occurred
rs.Movenext
loop

I searched in MSDN library and could not find any article / example.

Rob
Reply With Quote
  #8 (permalink)  
Old 05-16-04, 15:50
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Show us the code you use to instantiate "myFile". The more code you can show, the easier it is to diagnose.
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #9 (permalink)  
Old 05-17-04, 10:45
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Seppuku,

Here are some of my codes:

<%@ Language="VBscript" codepage=1251 %>
<html>
<head>
<title>get russian name</title>
<!-- #include file="inc_connstring.asp" -->
<meta http-equiv="Content-Type" content="text/html"; charset=windows-1251>
</head>
<body>
<%

Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set myFile = fs.CreateTextFile(Server.MapPath("\rtl\funstuff\fi le.txt"), True)
set connectme = server.createobject ("adodb.connection")
connectme.open(GetConnectionString())

sqltemp = "select OperatorName from databasetable "
set rs=Server.CreateObject("adodb.Recordset")
rs.open sqltemp,connectme

Do until rs.EOF
strLine=" "
for each x in rs.Fields
strLine= strLine & x.value & chr(9) // put chr(9) here or not did not make any difference
Next
myFile.writeline strLine // error occurred here
rs.MoveNext
Loop
myFile.close
rs.close
set rs = nothing
connectime.close

%>
</body>
</html>

Like I said, "invalid procedures call and arguments" error only occurred in myFile.writeline strLine caused the 'nvarchar' data from database!

If I commented the line, and it will execute without any error, but myFile is empty.

Rob
Reply With Quote
  #10 (permalink)  
Old 05-17-04, 10:48
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Is OperatorName a nullable field in the database?
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #11 (permalink)  
Old 05-17-04, 14:27
joshilat joshilat is offline
Registered User
 
Join Date: May 2004
Posts: 4
I got the same error before on writeLine method. I was able to fix the bug by checking for blank data. If the string you are writing to the CSV file is NULL, then you get this error. Try

If strline <> "" Then
myFile.writeline strline
End If
Reply With Quote
  #12 (permalink)  
Old 05-17-04, 15:25
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
OperatorName can't be NULL... So in this case no null data passed in. I think something to do with unicode data... But I have no problem display data on the Webpage, just can't write to the file???

Rob
Reply With Quote
  #13 (permalink)  
Old 05-18-04, 11:17
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
If you're writing unicode data, use this to create a unicode file:

Set myFile = fs.CreateTextFile(Server.MapPath("\rtl\funstuff\fi le.txt"), True, True)

CreateTextFile has three properties. Only one is required:

CreateTextFile(filename, [overwrite, unicode])

By default, overwrite is True, and unicode is False. So to set the file type to unicode, you need to force the third parameter to True.

This may help:
http://www.w3schools.com/asp/met_createtextfile.asp

Let us know if that helps.
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #14 (permalink)  
Old 05-18-04, 11:46
RTL RTL is offline
Registered User
 
Join Date: Feb 2004
Posts: 8
Thumbs up

Seppuku,

Took your suggestions and added one more flag to "true" and it worked. Thanks man and really appreciated...

Rob
Reply With Quote
  #15 (permalink)  
Old 05-18-04, 11:55
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
awesome
__________________
That which does not kill me postpones the inevitable.
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