When I follow through your example I get the following error message: Specified cast is not valid. and get the following stack trace:
[InvalidCastException: Specified cast is not valid.] System.Data.SqlClient.SqlDataReader.GetSqlDateTime(Int32 i) +46 System.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i) +33 admin.cstain.RSS.newsfeed.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\v2\newsfeed.aspx.vb:38 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +731
I am fairly new to asp.net from what I can gather this is happening on the time formatting. I am still unsure of all of the formatting options (one page i viewed show 17 examples alone and there are still more) so I am just lost of how to correct this. When I save the timestamp in my database i just use the standard formatting of the now command. which is m/d/yy 00:00:00 AM/PM I seen you were using R as your formatting type. I am unsure if that is the format you are saving it in your database or if you are reformatting your data to the R type. If you could help me I would appreciate it. I have also incluided the code I used on the page.
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Web
Imports System.Xml
Namespace cstain.RSS
Public Class newsfeed
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Clear()
Response.ContentType = "text/xml"
Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
objX.WriteStartDocument()
objX.WriteStartElement("rss")
objX.WriteAttributeString("version", "2.0")
objX.WriteStartElement("channel")
objX.WriteElementString("title", "Crimson Stain Productions")
objX.WriteElementString("link", "http://www.crimsonstain.net/newsfeed.aspx")
objX.WriteElementString("description", "The latest in what going on with Crimson Stain Productions")
objX.WriteElementString("copyright", "(c) 2004, Crimson Stain Productions, All rights reserved.")
objX.WriteElementString("ttl", "5")
Dim objConnection As New SqlConnection(ConfigurationSettings.AppSettings("MyConnectionString"))
objConnection.Open()
Dim sql As String = "SELECT TOP 10 title, main, postid, time FROM cstain_news ORDER BY time 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.crimsonstain.net/GetArticle.aspx?id=" + objReader.GetInt32(2).ToString())
objX.WriteElementString("pubDate", objReader.GetDateTime(3).ToString("G"))
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
Thanks,
Mike
|