sovanna
04-14-2010, 07:31 PM
Dear my friend,
My company is using jewelcart2000, it's shopping cart online.
Now I try to create xml file for google base but i am sturck at database connection.
could someone help me please?
Here is my xml file
----------------------------
Imports System
Imports System.Data
Imports System.Data.OleDB
Imports System.Configuration
Imports System.Web
Imports System.Xml
Namespace googleBaseFeed
Public Class createXMLFeed : Inherits System.Web.UI.Page
Sub Page_Load(sender as Object, e as EventArgs)
'### CLEAR THE BROWSER OUTPUT AND WRITE TEXT/XML HEADER
Response.Clear()
Response.ContentType = "text/xml"
Response.ContentEncoding = Encoding.UTF8
Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
objX.WriteStartDocument()
objX.WriteStartElement("rss")
objX.WriteAttributeString("version", "2.0")
objX.WriteAttributeString("xmlns:g", "http://base.google.com/ns/1.0")
objX.WriteStartElement("channel")
objX.WriteElementString("title", "Bella Findings House")
objX.WriteElementString("description", "Your website description")
objX.WriteElementString("link", "http://www.bellafindings.com/")
'### GET ALL PRODUCTS; DATABASE CONNECTION SPECIFIED IN WEB.CONFIG FILE
Dim myConnection as New oleDBConnection(ConfigurationManager.AppSettings("yourDNS"))
Dim myCommand as New oleDBCommand("SELECT idProduct, productTitle, description, price, productLink, imageUrl, productBrand, productType, productUPC, productWeight FROM products ORDER BY productId", myConnection)
Dim myReader As OleDbDataReader
Try
myConnection.Open()
myReader = myCommand.ExecuteReader()
While myReader.Read()
'### OPEN AND WRITE THE ITEM ELEMENT
objX.WriteStartElement("item")
objX.WriteElementString("id", myReader("productId").toString())
objX.WriteElementString("title", myReader("productTitle").toString())
objX.WriteElementString("description", Server.HtmlEncode(myReader("productDesc").toString()))
objX.WriteElementString("g:price", myReader("productPrice").toString())
objX.WriteElementString("link", myReader("productLink").toString())
objX.WriteElementString("g:image_link", myReader("productImage").toString())
objX.WriteElementString("g:brand", myReader("productBrand").toString())
objX.WriteElementString("g:product_type", myReader("productType").toString())
objX.WriteElementString("g:upc", myReader("productUPC").toString())
objX.WriteElementString("g:weight", myReader("productWeight").toString())
'### CLOSE ITEM
objX.WriteEndElement()
End While
myReader.Close()
Finally
myConnection.Close()
End Try
myConnection.Dispose()
'### CLOSE CHANNEL
objX.WriteEndElement()
'### CLOSE RSS
objX.WriteEndElement()
objX.WriteEndDocument()
objX.Flush()
objX.Close()
Response.End()
End Sub
End Class
End Namespace
My company is using jewelcart2000, it's shopping cart online.
Now I try to create xml file for google base but i am sturck at database connection.
could someone help me please?
Here is my xml file
----------------------------
Imports System
Imports System.Data
Imports System.Data.OleDB
Imports System.Configuration
Imports System.Web
Imports System.Xml
Namespace googleBaseFeed
Public Class createXMLFeed : Inherits System.Web.UI.Page
Sub Page_Load(sender as Object, e as EventArgs)
'### CLEAR THE BROWSER OUTPUT AND WRITE TEXT/XML HEADER
Response.Clear()
Response.ContentType = "text/xml"
Response.ContentEncoding = Encoding.UTF8
Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
objX.WriteStartDocument()
objX.WriteStartElement("rss")
objX.WriteAttributeString("version", "2.0")
objX.WriteAttributeString("xmlns:g", "http://base.google.com/ns/1.0")
objX.WriteStartElement("channel")
objX.WriteElementString("title", "Bella Findings House")
objX.WriteElementString("description", "Your website description")
objX.WriteElementString("link", "http://www.bellafindings.com/")
'### GET ALL PRODUCTS; DATABASE CONNECTION SPECIFIED IN WEB.CONFIG FILE
Dim myConnection as New oleDBConnection(ConfigurationManager.AppSettings("yourDNS"))
Dim myCommand as New oleDBCommand("SELECT idProduct, productTitle, description, price, productLink, imageUrl, productBrand, productType, productUPC, productWeight FROM products ORDER BY productId", myConnection)
Dim myReader As OleDbDataReader
Try
myConnection.Open()
myReader = myCommand.ExecuteReader()
While myReader.Read()
'### OPEN AND WRITE THE ITEM ELEMENT
objX.WriteStartElement("item")
objX.WriteElementString("id", myReader("productId").toString())
objX.WriteElementString("title", myReader("productTitle").toString())
objX.WriteElementString("description", Server.HtmlEncode(myReader("productDesc").toString()))
objX.WriteElementString("g:price", myReader("productPrice").toString())
objX.WriteElementString("link", myReader("productLink").toString())
objX.WriteElementString("g:image_link", myReader("productImage").toString())
objX.WriteElementString("g:brand", myReader("productBrand").toString())
objX.WriteElementString("g:product_type", myReader("productType").toString())
objX.WriteElementString("g:upc", myReader("productUPC").toString())
objX.WriteElementString("g:weight", myReader("productWeight").toString())
'### CLOSE ITEM
objX.WriteEndElement()
End While
myReader.Close()
Finally
myConnection.Close()
End Try
myConnection.Dispose()
'### CLOSE CHANNEL
objX.WriteEndElement()
'### CLOSE RSS
objX.WriteEndElement()
objX.WriteEndDocument()
objX.Flush()
objX.Close()
Response.End()
End Sub
End Class
End Namespace