| | |
Help with a cast error
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 4
Reputation:
Solved Threads: 0
I'm trying to migrate some code to generate an rss feed from classic ASP to .NET (because its cleaner). I've got it working perfectly for the first feed I try, but when I tried to modify the code for the next feed I get a Specified cast 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: Specified cast is not valid.
The only thing different in the code from feed a to feed b is the call to the different connection string:
I'm not sure if its the connection I added to my web config file (the tables are on 2 separate databases)
Any assistance would be appreciated!
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: Specified cast is not valid.
The only thing different in the code from feed a to feed b is the call to the different connection string:
ASP.NET Syntax (Toggle Plain Text)
Namespace LMC.news Public Class news Inherits System.Web.UI.Page Sub Page_Load(sender As Object, e As System.EventArgs) Response.Clear() Response.ContentType = "text/xml" Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8) objX.WriteStartDocument() Dim strPI strPI = "type='text/xsl' href='news.xsl'" objX.WriteProcessingInstruction("xml-stylesheet", strPI) objX.WriteStartElement("rss") objX.WriteAttributeString("version", "2.0") objX.WriteStartElement("channel") objX.WriteElementString("title", "Press Releases") objX.WriteElementString("link", "/news/news.aspx") objX.WriteElementString("description", "Recent Press Releases from the Office of Communications") objX.WriteElementString("language", "en-us") objX.WriteElementString("copyright", "(c) 2006 Le Moyne College. All rights reserved.") objX.WriteElementString("webmaster", "webmaster@lemoyne.edu") objX.WriteElementString("ttl", "20") Dim objConnection As New SqlConnection(ConfigurationSettings.AppSettings("wwwConnection")) objConnection.Open() Dim sql As String = "SELECT * FROM press_releases where press_post > '1/1/2007' order by press_post desc" Dim objCommand As New SqlCommand(sql, objConnection) Dim objReader As SqlDataReader = objCommand.ExecuteReader() While objReader.Read() objX.WriteStartElement("item") objX.WriteElementString("title", objReader.GetString(0)) objX.WriteElementString("description", objReader.GetString(1)) objX.WriteElementString("link", "http://www.lemoyne.edu/communications/Comm_Press.asp?id=" + objReader.GetInt32(2).ToString()) objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("R")) objX.WriteEndElement() End While objReader.Close() objConnection.Close() objX.WriteEndElement() objX.WriteEndElement() objX.WriteEndDocument() objX.Flush() objX.Close() Response.End() End Sub End Class End Namespace
ASP.NET Syntax (Toggle Plain Text)
<appSettings> <add key="strConnection" value="server=mssql;uid=xxxxx;pwd=xxxxx;database=xxxxx" /> <add key="wwwConnection" value="server=mssql;uid=xxxxxx;pwd=xxxxx;database=xxxxx" /> </appSettings>
![]() |
Similar Threads
- error C2664 (C++)
- broken code (C++)
- help with array problem (C)
- Calling a class upon button click (C#)
- Adding memberfunctions into a class? (C++)
- Array problems (C++)
- OOP char [8] to char (C++)
- Real number to binary? (C)
- adding data into an char array (C++)
Other Threads in the ASP.NET Forum
- Previous Thread: ? ItemTemplate in TemplateField of a GridView
- Next Thread: Problem with ContentPlaceHolder content format in IE, ok in Firefox
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





