---
title: "'Field' to 'String' is not valid."
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/75743-field-to-string-is-not-valid"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "Choronzon"
published: "2003-05-03T11:33:07.000Z"
updated: "2003-05-03T14:41:44.000Z"
replies: 6
views: 441
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/75743-field-to-string-is-not-valid"
---

# 'Field' to 'String' is not valid.

## #1 — Choronzon, 2003-05-03T11:33Z

Försöker göra om en asp sida till aspx och får detta mess..hur ska jag göra? tpfh

```
Cast from type 'Field' to type 'String' is not valid. 
Description: An unhandled exception occurred during the execution of the current web request. 
Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Cast from type 'Field' to type 'String' is not valid.

Source Error: 

Line 62: 	StrTStr = replace(StrRs("destination"),"&","&amp;amp;")
```

edit:
Är en funktion som byter ut &-tecknen mot &amp;amp;

Permalänk: https://www.webforum.nu/p/75743

## #2 — renholm, 2003-05-03T12:43Z

Kan tänka mig att detta kan fungera: StrTStr = replace(StrRs("destination").ToString(),"&","&amp;")

Permalänk: https://www.webforum.nu/p/1033705

## #3 — Choronzon, 2003-05-03T13:12Z

Jo det funkade, men ett annat problem dök upp. Det jag vill åstadkomma är rader med 
Datum - länk. Där länken har en beskrivande text.

Och det som skrivs  ut nu är  
System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject osv.

Istället för 
030402 Länken
030202 Länken
030103 Länken osv.
 

```
i headern har jag:
<%@ Page aspcompat=true Debug="true"%> 
Response.Buffer = true

och koden:
Dim ObjCn, StrRs
Dim StrTStr
ObjCn = Server.CreateObject("ADODB.Connection")
	ObjCn.Open ("-acesskoppling-")
StrRs = ObjCn.execute("SELECT * FROM links ORDER BY datum desc")
	Do until StrRs.EOF
	StrTStr = replace(StrRs("destination").ToString(),"&","&amp;")
	.write ("<tr>")
	.write ("<td>")
	.write (StrRs("datum"))
	.write ("</td>")
	.write ("<td>")
	.write ("<a href=""")
	.write (StrTStr)
	.write (""" title=""" )
	.write (StrTStr)
	.write (""">")
	StrTStr = replace(StrRs("description").ToString(),"&","&amp;")
	StrTStr = replace(StrTStr, "å","&aring;")
	StrTStr = replace(StrTStr, "ä","&auml;")
	StrTStr = replace(StrTStr, "ö","&ouml;")
	StrTStr = replace(StrTStr, "Å","&Aring;")
	StrTStr = replace(StrTStr, "Ä","&Auml;")
	StrTStr = replace(StrTStr, "Ö","&Ouml;")
	.write (StrTStr)
	.write ("</a></td>")
	.write ("</tr>")
	StrRs.Movenext
	Loop
	StrRs.close
StrRs = nothing
	ObjCn.close
ObjCn = nothing
```

Permalänk: https://www.webforum.nu/p/1033713

## #4 — ptype, 2003-05-03T13:27Z

måste köra ToString()-metoden

Du gör:

```
write (StrRs("datum"))
```

vilket skriver ut objekttypen.

Prova

```
write (StrRs("datum").ToString())
```

alternativt

```
write (Convert.ToString(StrRs("datum")))
```

om inte första alternativet fungerar.

Permalänk: https://www.webforum.nu/p/1033724

## #5 — Choronzon, 2003-05-03T13:49Z

Testade alla tre varianterna men får samma resultat

Utskrift:  
System.\__ComObject System.\__ComObject System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject System.\__ComObject System.\__ComObject 
System.\__ComObject System.\__ComObject System.\__ComObject System.\__ComObject osv.

Kod:

```
StrRs = ObjCn.execute("SELECT * FROM links ORDER BY datum desc")
	Do until StrRs.EOF
	StrTStr = replace(StrRs("destination").ToString(),"&","&amp;")
	.write ("<tr>")
	.write ("<td>")
	.write(Convert.ToString(StrRs("datum")))
	.write (StrRs("datum").ToString())
	.write (StrRs("datum"))
	.write ("</td>")
	.write ("<td>")
	.write ("<a href=""")
	.write (StrTStr)
	.write (""" title=""" )
	.write (StrTStr)
	.write (""">")
	StrTStr = replace(StrRs("description").ToString(),"&","&amp;")
	StrTStr = replace(StrTStr, "å","&aring;")
	StrTStr = replace(StrTStr, "ä","&auml;")
	StrTStr = replace(StrTStr, "ö","&ouml;")
	StrTStr = replace(StrTStr, "Å","&Aring;")
	StrTStr = replace(StrTStr, "Ä","&Auml;")
	StrTStr = replace(StrTStr, "Ö","&Ouml;")
	.write (StrTStr)
	.write ("</a></td>")
	.write ("</tr>")
	StrRs.Movenext
	Loop
	StrRs.close
StrRs = nothing
	ObjCn.close
ObjCn = nothing
```

Permalänk: https://www.webforum.nu/p/1033750

## #6 — ptype, 2003-05-03T14:33Z

va?
eh prova då

```
write(Convert.ToString(StrRs("datum").ToString()))
```

Permalänk: https://www.webforum.nu/p/1033784

## #7 — Choronzon, 2003-05-03T14:41Z

Samma sak..

utskrift:
System.\__ComObjectSystem.\__ComObjectSystem.\__ComObjectSystem.\__ComObjectSystem.\__ComObject
System.\__ComObjectSystem.\__ComObjectSystem.\__ComObjectSystem.\__ComObjectSystem.\__ComObjectosv.

skickar hela koden.

```
<%@ Page Language="VB" aspcompat=true Debug="true"%>
<table>
<%
Response.Buffer = true
Dim ObjCn, StrRs
Dim StrTStr
with response
ObjCn = Server.CreateObject("ADODB.Connection")
	ObjCn.Open ("driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("db/db.mdb")&";pwd=1")
StrRs = ObjCn.execute("SELECT * FROM links ORDER BY datum desc")
	Do until StrRs.EOF
	StrTStr = replace(StrRs("destination").ToString(),"&","&")
	.write ("<tr>")
	.write ("<td>")
	.write(Convert.ToString(StrRs("datum").ToString()))
	.write(Convert.ToString(StrRs("datum")))
	.write (StrRs("datum").ToString())
	.write (StrRs("datum"))
	.write ("</td>")
	.write ("<td>")
	.write ("<a href=""")
	.write (StrTStr)
	.write (""" title=""" )
	.write (StrTStr)
	.write (""">")
	StrTStr = replace(StrRs("description").ToString(),"&","&")
	StrTStr = replace(StrTStr, "å","å")
	StrTStr = replace(StrTStr, "ä","ä")
	StrTStr = replace(StrTStr, "ö","ö")
	StrTStr = replace(StrTStr, "Å","Å")
	StrTStr = replace(StrTStr, "Ä","Ä")
	StrTStr = replace(StrTStr, "Ö","Ö")
	.write (StrTStr)
	.write ("</a></td>")
	.write ("</tr>")
	StrRs.Movenext
	Loop
	StrRs.close
StrRs = nothing
	ObjCn.close
ObjCn = nothing
end with
%>
</table>
```

Permalänk: https://www.webforum.nu/p/1033793

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/75743-field-to-string-is-not-valid
