| | |
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 2.0 3.5 activexcontrol advice ajax appliances asp asp.net beginner bottomasp.net box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form forms gridview gudi homeedition hosting iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings redirect registration relationaldatabases rotatepage search security select serializesmo.table sessionvariables silverlight smartcard sql ssl tracking treeview typeof validatedate validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopment wizard xml xsl





