I'm trying to learn what the proper or best way to pull data from an html table and import it into a sql table. Every week we get a html document that I must insert into a table. I usually just use sql management to import it into a blank table then merge it with the current table. I know some c# so I wanted to create an importer to automated a bit.
I was thinking of just reading each line and lopping through looking for and and insert the data like that. Is that the best way, or is there a better way to do it?
Thanks
Here is example of the html file. The 1st columns are the column names.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
br
{mso-data-placement:same-cell;}
</style>
</head>
<body>
<table border="1">
<tr><td><b>#</b></td>
<td><b>Asset Manager</b></td>
<td><b>Billing Address</b></td>
<td><b>Billing City</b></td>
<td><b>Billing State</b></td>
<td><b>Billing Zip Code</b></td>
<td><b>Contract Amount</b></td>
<td><b>DUNS Number</b></td>
<td><b>FEIN</b></td>
</tr>
<tr>
<td>1</td>
<td style="mso-number-format:\@">Jim Bob</td>
<td style="mso-number-format:\@">2500 N. Park Pkwy, Suite 600</td>
<td style="mso-number-format:\@">Plano</td>
<td>Texas</td>
<td style="mso-number-format:\@">75093</td>
<td>$0.00</td>
<td style="mso-number-format:\@"></td>
<td style="mso-number-format:\@"></td>
</tr>
</table>
</body>
</html>
So far I created a button that will grab the document name. Also have the SQLConnection set to the correct server.
private void buttonBrowse_Click(object sender, EventArgs e)
{
var DB = new System.Windows.Forms.OpenFileDialog();
if (DB.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string fileToOpen = DB.FileName;
textBoxImport.Text = fileToOpen;
}
}