Cast from type 'Field' to type 'String'

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Cast from type 'Field' to type 'String'

    Hi,

    Getting the above error - further info shown below

    Line 36: II2 = 0
    Line 37: response.write ("var questions" & II & " = new Array();" &
    chr(10))
    Line 38: oCmd.CommandText = "select distinct questions from whitepage
    where topic ='" & oRs("topic") & "'"
    Line 39: oRs2.open (oCmd, , 0, 1)
    Line 40: if not(oRs2.BOF and oRs2.EOF) then

    and

    [InvalidCastException: Cast from type 'Field' to type 'String' is not
    valid.]
    Microsoft.VisualBasic.CompilerServices.StringType. FromObject(Object
    Value) +616
    Microsoft.VisualBasic.CompilerServices.ObjectType. StrCatObj(Object vLeft,
    Object vRight) +138
    ASP.questions_aspx.__Render__control1(HtmlTextWrit er __output, Control
    parameterContainer) in d:\clients\4it4all.com\www\questions.aspx:38
    System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
    System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Page.ProcessRequestMain() +1929

    Using the code:-

    oCmd.CommandText = "select distinct topic from whitepage where topic <> ''
    and topic is not NULL"
    oRs.open (oCmd, , 0, 1)
    if not(oRs.BOF and oRs.EOF) then
    while not oRs.EOF
    II2 = 0
    response.write ("var questions" & II & " = new Array();" & chr(10))
    oCmd.CommandText = "select distinct questions from whitepage where topic
    ='" & oRs("topic") & "'"
    oRs2.open (oCmd, , 0, 1)
    if not(oRs2.BOF and oRs2.EOF) then
    while not oRs2.EOF
    response.write ("questions" & II & "[" & II2 & "] = """ &
    replace(oRs2("questions"),chr(10),"") & """;" & chr(10))
    oRs2.moveNext
    II2 = II2 + 1
    End While
    end if
    oRs2.close
    II = II + 1
    oRs.moveNext
    End While
    end if
    oRs.close

    Can anyone shed any light on this please

    Cheers

    Steve


    Guest

  2. Similar Questions and Discussions

    1. how to type cast getjsobject form vb.net to c#
      how to type cast getjsobject form vb.net to c#
    2. Object of type 'System.String' cannot be converted to type 'System
      I'm trying to get a control from metabuilders.com dual list)to work under ASP.NET 2.0. It worked find under 1.1 and then when i migrated my...
    3. Problem with character palette and Tracking field: can't type zero after type is modified
      System: Illustrator CS, Panther 10.3.3 Try this: Create a few characters of type. Select some letters and change their tracking (Option + Command...
    4. cast from datetime type to smalldatetime type?
      Hi, How can I cast from datetime type to smalldatetime type. I get the records from a table which has got a datetime type column but I want to...
    5. Cast from type 'DBNull' to type 'String' is not valid error
      Trying to add an insert button Sub btnAddRow_Click event for adding a row to the datagrid and dataset back to SQL. Had it working per the...
  3. #2

    Default Re: Cast from type 'Field' to type 'String'

    > Line 36: II2 = 0
    > Line 37: response.write ("var questions" & II & " = new Array();" &
    > chr(10))
    > Line 38: oCmd.CommandText = "select distinct questions from whitepage
    > where topic ='" & oRs("topic") & "'"
    > Line 39: oRs2.open (oCmd, , 0, 1)
    > Line 40: if not(oRs2.BOF and oRs2.EOF) then
    First, you shouldn't be using nested recordsets; have you considered a join?

    Second, if you are using ASP.NET, please ask questions in an ASP.NET group,
    e.g.
    [url]news://msnews.microsoft.com/microsoft.public.dotnet.framework.aspnet[/url]

    > [InvalidCastException: Cast from type 'Field' to type 'String' is not
    > valid.]
    > Microsoft.VisualBasic.CompilerServices.StringType. FromObject(Object
    > Value) +616
    > Microsoft.VisualBasic.CompilerServices.ObjectType. StrCatObj(Object
    vLeft,
    > Object vRight) +138
    > ASP.questions_aspx.__Render__control1(HtmlTextWrit er __output, Control
    > parameterContainer) in d:\clients\4it4all.com\www\questions.aspx:38
    > System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
    > System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Page.ProcessRequestMain() +1929

    Aaron Bertrand [MVP] Guest

  4. #3

    Default Re: Cast from type 'Field' to type 'String'

    I think in .NET you have to fully qualify the value as in:

    oRs2("questions").value

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    [url]www.ielearning.com[/url]


    <steve@i-db.com> wrote in message
    news:7J5sb.6965$lm1.49079@wards.force9.net...
    > Hi,
    >
    > Getting the above error - further info shown below
    >
    > Line 36: II2 = 0
    > Line 37: response.write ("var questions" & II & " = new Array();" &
    > chr(10))
    > Line 38: oCmd.CommandText = "select distinct questions from whitepage
    > where topic ='" & oRs("topic") & "'"
    > Line 39: oRs2.open (oCmd, , 0, 1)
    > Line 40: if not(oRs2.BOF and oRs2.EOF) then
    >
    > and
    >
    > [InvalidCastException: Cast from type 'Field' to type 'String' is not
    > valid.]
    > Microsoft.VisualBasic.CompilerServices.StringType. FromObject(Object
    > Value) +616
    > Microsoft.VisualBasic.CompilerServices.ObjectType. StrCatObj(Object
    vLeft,
    > Object vRight) +138
    > ASP.questions_aspx.__Render__control1(HtmlTextWrit er __output, Control
    > parameterContainer) in d:\clients\4it4all.com\www\questions.aspx:38
    > System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
    > System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    > System.Web.UI.Page.ProcessRequestMain() +1929
    >
    > Using the code:-
    >
    > oCmd.CommandText = "select distinct topic from whitepage where topic <> ''
    > and topic is not NULL"
    > oRs.open (oCmd, , 0, 1)
    > if not(oRs.BOF and oRs.EOF) then
    > while not oRs.EOF
    > II2 = 0
    > response.write ("var questions" & II & " = new Array();" & chr(10))
    > oCmd.CommandText = "select distinct questions from whitepage where topic
    > ='" & oRs("topic") & "'"
    > oRs2.open (oCmd, , 0, 1)
    > if not(oRs2.BOF and oRs2.EOF) then
    > while not oRs2.EOF
    > response.write ("questions" & II & "[" & II2 & "] = """ &
    > replace(oRs2("questions"),chr(10),"") & """;" & chr(10))
    > oRs2.moveNext
    > II2 = II2 + 1
    > End While
    > end if
    > oRs2.close
    > II = II + 1
    > oRs.moveNext
    > End While
    > end if
    > oRs.close
    >
    > Can anyone shed any light on this please
    >
    > Cheers
    >
    > Steve
    >
    >

    Mark Schupp Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139