Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
I have got the contents of a website by parsing the html tags using HTMLAGILITY pack & store it in a .html file. Now i want to store those contents in access database? how do i achieve it using c#?

this is how my .html file contents look like
VB
Date       Time             Lat       Lon  Depth   Mag Magt  Nst Gap 

2002/01/10 00:44:51.53  40.4415 -126.0167  25.37  3.92   Md   56 269  


the heading should be column names & the contents below should be the data value
Posted
Updated 23-Jul-13 6:19am
v4
Comments
[no name] 21-Jul-13 11:13am    
You connect to your database, write a query to insert the data that you want, execute the query and close the connection.

1 solution

This tutorial demonstrates using a Microsoft Access database from a C# application[^]

[update] Parsing the input text:

One simple solution for your pasting is:

Split the text to elements, you will get an array of string
{ "Date", "Time", "Lat", .... , "2002/01/10", "00:44:51.53", "40.4415" .... }

then go through the values and use them.
that will be good if you are sure about the order in which those will appear in the incoming text.
This can be achieved easily like this:
C#
string[] values = Regex.Split(YourText, @"\D+");
foreach (string val in values)
{
   // do stuff with the elements ...
}

// OR this:
double LAT = Convert.ToDouble(values[11]); // take the elements according to their position.
double LON = Convert.ToDouble(values[12]);
// and so on ...
However, I strongly suggest you learn C# Regex to accommodate for any needs that rise due to the formatting of the text, future changes and generally speaking, Regex in my opintion is pretty much a must tool for a developer.


Some Regex links:
The 30 Minute Regex Tutorial[^]
Learn Regular Expressions (RegEx) with Ease[^]

[/update]

Good luck,
Edo
 
Share this answer
 
v3
Comments
Member 8657306 22-Jul-13 5:18am    
i knw bout using the oledb obect, but how do i map the contents of this file to the db?
Joezer BH 22-Jul-13 5:48am    
Do have need help with parsing your text/html?
Member 8657306 22-Jul-13 11:59am    
yes i want help to parse that doc to access, plzz help
Joezer BH 23-Jul-13 1:30am    
Ok, so I guess the title of the question should have been "How to parse a text/html document"
You can edit your question by clicking the "Improve question" link
Also - when you post a reply to a comment, click the "Reply" link.

Now, if parsing is the issue, show us your text to parse and the requirements from that text, meaning how you recognize the parts for each field in the DB etc and we will pick up from there.
Member 8657306 23-Jul-13 4:23am    
@maimonides- the text to be parsed is as described above i.e datetime long,lat etc...
from that i nly want the datetime contents,lat,lon,depth,mag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900