Results 1 to 15 of 15
  1. #1
    Join Date
    May 2004
    Posts
    4

    Unanswered: 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


  2. #2
    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?

  3. #3
    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?

  4. #4
    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.

  5. #5
    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.

  6. #6
    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.

  7. #7
    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

  8. #8
    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.

  9. #9
    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

  10. #10
    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.

  11. #11
    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

  12. #12
    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

  13. #13
    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.

  14. #14
    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

  15. #15
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    awesome
    That which does not kill me postpones the inevitable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •