views:

86

answers:

3
**http://www.dsebd.org/latest_PE_all2_08.php**

above url contain a html table.I want to save this table value on XML and also want to save this table value on database MS2008.

How to save html table values on database

A: 

Actually, on a typical dynamic HTML page, the table's values are loaded from the database. But, if you want, you can still parse the page's source, and save every row's values into your database. Is that what you want to do?

moz
show me some syntax
shamim
+1  A: 

Hi,

You could use HTML Agility pack like so:

    WebClient webClient = new WebClient();
    const string strUrl = "http://www.myspace.com/centuryman";

    // Setup proxy for internal stuff
    //System.Net.WebProxy pry = new System.Net.WebProxy("194.80.164.8", 80);
    //pry.Credentials = CredentialCache.DefaultCredentials;
    //WebRequest.DefaultWebProxy = pry;

    Stream s = webClient.OpenRead(strUrl);

    HtmlDocument doc = new HtmlDocument();
    doc.Load(s);

    HtmlNode link = doc.DocumentNode.SelectNodes("//*[@id='profile_bandschedule']")[0];

This would return you a enumarable object which you could loop around and insert values of the html into the database.

See another example:

http://stackoverflow.com/questions/846994/how-to-use-html-agility-pack

Mantisimo
to use HtmlDocument and HtmlNode which name space i need to add on my project.VS 2008 Show me message add references
shamim
Look at the link I added at the bottom, there is a more comprehensive example there. It also contains the download link for the HTML Agiliy pack. You'll need to download that. Add the dll to your bin directry and then reference this in your vs project.
Mantisimo
A: 

You can parse the table with jQuery, create client side array or object and send it back to the server with an AJAX call or form post.

HTML:

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;
<![endif]-->   
</head>
<body>
  <table id="tableData">
     <tr id="tableHeader">
        <td>col1</td>
        <td>col2</td>
      </tr>    
      <tr id="tableRow">
        <td>data1row1</td>
        <td>data2row2</td>
      </tr>
      <tr id="tableRow">         
        <td>data1row2</td>
        <td>data2row3</td>
      </tr>
  </table>
</body>
</html>

SCRIPT:

$(document).ready(function() {
     //parse all the data
     $('#tableData tr').each(function() {
         if($(this).attr('id')=='tableHeader')
         {
           alert('this is the header row');          
         }    
         $('td', this).each(function() {             
              alert($(this).html());
         });

    });

   //post the form or send data via AJAX

});
rick schott