473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create 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 2337
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
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...
17
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...
4
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 ...
29
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...
0
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...
0
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...
1
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
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
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...
0
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,...
0
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,...
0
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.