473,831 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help converting .xml feed to SQL

49 New Member
Hi everyone,
I am currently working on a project that pulls data from sql and displays it in an html file. This is working fine, but I am trying to make it a little more fancy using this cool source code found here:

http://mattberseth.com/blog/2007/12/...gest_styl.html

In the source code, it is pulling dummy data from an .xml file that stores all of the data. I would like to change the source of the data to a table in my sql 2005 (my real data). Can someone help me make the necessary changes to pull my data from SQL? Sorry for my beginner questions. All help is appreciated!

Here is my C# code that references the .xml file;


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.ComponentModel;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.IO;
  6. using System.Web;
  7.  
  8. /// <summary>
  9. /// Summary description for CustomerDataObject
  10. /// </summary>
  11. [DataObject(true)]
  12. public class CustomersDataObject
  13. {
  14.     /// <summary>
  15.     /// 
  16.     /// </summary>
  17.     private DataSet _customers;
  18.  
  19.     /// <summary>
  20.     /// 
  21.     /// </summary>
  22.     public CustomersDataObject()
  23.     {
  24.         this._customers = HttpContext.Current.Session["Customers"] as DataSet;
  25.  
  26.         if (this._customers == null)
  27.         {
  28.             this._customers = new DataSet();
  29.             this._customers.ReadXml(HttpContext.Current.Server.MapPath(@"App_Data\customers.xml"));
  30.  
  31.             HttpContext.Current.Session["Customers"] = this._customers;
  32.         }
  33.     }
  34.  
  35.     /// <summary>
  36.     /// 
  37.     /// </summary>
  38.     public DataTable CustomerTable
  39.     {
  40.         get { return this._customers.Tables["customers"]; }
  41.     }
  42.  
  43.     /// <summary>
  44.     /// 
  45.     /// </summary>
  46.     /// <returns></returns>
  47.     public DataView Select(string propertyName, string propertyValue)
  48.     {
  49.         EnumerableRowCollection<DataRow> query = null;
  50.         if (string.IsNullOrEmpty(propertyName) || string.IsNullOrEmpty(propertyValue))
  51.         {
  52.             query =
  53.                 from customer in this.CustomerTable.AsEnumerable()
  54.                 select customer;
  55.         }
  56.         else
  57.         {
  58.             query =
  59.                 from customer in this.CustomerTable.AsEnumerable()
  60.                 where customer.Field<string>(propertyName).Equals(propertyValue, StringComparison.CurrentCultureIgnoreCase)
  61.                 select customer;
  62.         }
  63.  
  64.         return query.AsDataView();
  65.     }
  66.  
  67.     /// <summary>
  68.     /// 
  69.     /// </summary>
  70.     /// <param name="columnName"></param>
  71.     /// <param name="count"></param>
  72.     /// <param name="prefix"></param>
  73.     /// <returns></returns>
  74.     public string[] GetCompletionList(string columnName, string prefix, int count)
  75.     {
  76.         //  find all of the rows that have values that start with
  77.         //  the provided prefix
  78.         EnumerableRowCollection<DataRow> query =
  79.             from customer in this.CustomerTable.AsEnumerable()
  80.             where customer.Field<string>(columnName).ToLower().StartsWith(prefix.ToLower())
  81.             select customer;
  82.  
  83.         DataView view = query.AsDataView();
  84.  
  85.         //  only return distinct values
  86.         System.Collections.Generic.List<string> items = new System.Collections.Generic.List<string>();
  87.         #region Distinct
  88.         for (int i = 0; i < count && i < view.Count; i++)
  89.         {
  90.             string value = view[i][columnName].ToString();
  91.             if (!items.Contains(value))
  92.             {
  93.                 items.Add(value);
  94.             }
  95.         }
  96.         #endregion
  97.  
  98.         //  return the items
  99.         return items.ToArray(); 
  100.     }
  101. }
Aug 28 '09 #1
1 2354
ck9663
2,878 Recognized Expert Specialist
Actually it's more of a C# question than a SQL Server question. Find that portion that you connect your code to an xml file and try replacing that with a DSN-Less connection to a SQL server. I would think the SELECT statement would be the same.

Good luck!!!

--- CK
Aug 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3343
by: Kevin T. Ryan | last post by:
Hi all - I'm somewhat new to python (about 1 year), and I'm trying to write a program that opens a file like object w/ urllib.urlopen, and then parse the data by passing it to a class that subclasses HTMLParser.HTMLParser. On the web page, however, there is javascript - and I think that is causing an error in parsing the data. Here's the error: Traceback (most recent call last): File "<stdin>", line 1, in ?
17
29840
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements such as href, img, b, p, etc into XML? I've seen someone use the following in their RSS feed but I don't like it because <pre> doesn't produce a nice format:
4
2222
by: Chris | last post by:
Hi, I found this code that can solve a problem I have. It sends print direct to printer. Imports System Imports System.Text Imports System.Runtime.InteropServices <StructLayout(LayoutKind.Sequential)> _ Public Structure DOCINFO<MarshalAs(UnmanagedType.LPWStr)>
29
3915
by: Armand Karlsen | last post by:
I have a website ( http://www.zen62775.zen.co.uk ) that I made HTML 4.01 Transitional and CSS compliant, and I'm thinking of converting it into XHTML to learn a little about it. Which XHTML variant would you recommend? The w3c HTML validator mentions XHTML 1.0 Transitional, Basic, Strict, and XHTML 1.1. Would I be able to make my existing CSS work in the XHTML page without modification to the .css file?
0
903
by: chuck | last post by:
Hello, We are converting to a VB Dot Net application . We have a grid with multiple columns. The headings in each of the columns are long and so we have to wrap the headings and display them in two lines as the header...similar to the wrapping property in Excel. The Carriage return and line feed does not seem to work. It does'nt look like you can change the header properties of a grid in Dot net. if I have "Last two Year sales" as the...
0
1602
by: Jon | last post by:
All, I'm extremely new to XML and have been given a project that at this time seems way over my head. Was hoping someone here could help. Basically, I need a page that functions much like pages at www.feedburner.com. When you publish a feed, users can click on any files associated with the feed that are displayed in a nice looking webpage format, and if you want to put the feed into iTunes, you simply copy the same URL into your...
1
1579
by: shotokan99 | last post by:
hi guys, i want to have rss on my site and the page is written in php (mypage.php). what are the things i need? how to start to with it? pls help.. tnx
2
6594
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Is it possible to convert a microsoft word document to pdf in .net code. If anyone has done this before, please let me know.
9
2572
by: bhass | last post by:
I'm trying to make a basic RSS feed generator. I'm still a newb and I really need help. My aim is to have the user input all their desired settings then create an XML file in the same directory with all of their RSS settings. First I'd like it to ask the user how many articles it wants to put in the RSS feed. So it can loop the adding articles bit that many times. Then after the user inputting all their desired options, for it to display,...
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10494
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10534
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10207
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.