Private Function ConvertHTMLTablesToDataSet(ByVal HTML As String) As DataSet
' Declarations
Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim dc As DataColumn
Dim TableExpression As String = "
Dim HeaderExpression As String = "
Dim RowExpression As String = "
Dim ColumnExpression As String = "
Dim HeadersExist As Boolean = False
Dim iCurrentColumn As Integer = 0
Dim iCurrentRow As Integer = 0
' Get a match for all the tables in the HTML
Dim Tables As MatchCollection = Regex.Matches(HTML, TableExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase)
' Loop through each table element
For Each Table As Match In Tables
' Reset the current row counter and the header flag
iCurrentRow = 0
HeadersExist = False
' Add a new table to the DataSet
dt = New DataTable
' Create the relevant amount of columns for this table (use the headers if they exist, otherwise use default names)
If Table.Value.Contains("
HeadersExist = True
' Get a match for all the rows in the table
Dim Headers As MatchCollection = Regex.Matches(Table.Value, HeaderExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase)
' Loop through each header element
For Each Header As Match In Headers
dt.Columns.Add(Header.Groups(1).ToString)
Next
Else
For iColumns As Integer = 1 To Regex.Matches(Regex.Matches(Regex.Matches(Table.Value, TableExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase).Item(0).ToString, RowExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase).Item(0).ToString, ColumnExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase).Count
dt.Columns.Add("Column " & iColumns)
Next
End If
' Get a match for all the rows in the table
Dim Rows As MatchCollection = Regex.Matches(Table.Value, RowExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase)
' Loop through each row element
For Each Row As Match In Rows
' Only loop through the row if it isn't a header row
If Not (iCurrentRow = 0 And HeadersExist = True) Then
' Create a new row and reset the current column counter
dr = dt.NewRow
iCurrentColumn = 0
' Get a match for all the columns in the row
Dim Columns As MatchCollection = Regex.Matches(Row.Value, ColumnExpression, RegexOptions.Multiline Or RegexOptions.Singleline Or RegexOptions.IgnoreCase)
' Loop through each column element
For Each Column As Match In Columns
' Add the value to the DataRow
dr(iCurrentColumn) = Column.Groups(1).ToString
' Increase the current column
iCurrentColumn += 1
Next
' Add the DataRow to the DataTable
dt.Rows.Add(dr)
End If
' Increase the current row counter
iCurrentRow += 1
Next
' Add the DataTable to the DataSet
ds.Tables.Add(dt)
Next
Return ds
End Function

Lalit MPosted Sep 27, 2011, 6:07 AM
private DataSet ConvertHTMLTablesToDataSet(string HTML)
{
// Declarations
DataSet ds = new DataSet();
DataTable dt = default(DataTable);
DataRow dr = default(DataRow);
DataColumn dc = default(DataColumn);
string TableExpression = "
string HeaderExpression = "
string RowExpression = "
string ColumnExpression = "
bool HeadersExist = false;
int iCurrentColumn = 0;
int iCurrentRow = 0;
// Get a match for all the tables in the HTML
MatchCollection Tables = Regex.Matches(HTML, TableExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Loop through each table element
foreach (Match Table in Tables) {
// Reset the current row counter and the header flag
iCurrentRow = 0;
HeadersExist = false;
// Add a new table to the DataSet
dt = new DataTable();
// Create the relevant amount of columns for this table (use the headers if they exist, otherwise use default names)
if (Table.Value.Contains("
HeadersExist = true;
// Get a match for all the rows in the table
MatchCollection Headers = Regex.Matches(Table.Value, HeaderExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Loop through each header element
foreach (Match Header in Headers) {
dt.Columns.Add(Header.Groups(1).ToString);
}
} else {
for (int iColumns = 1; iColumns <= Regex.Matches(Regex.Matches(Regex.Matches(Table.Value, TableExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase).Item(0).ToString, RowExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase).Item(0).ToString, ColumnExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase).Count; iColumns++) {
dt.Columns.Add("Column " + iColumns);
}
}
// Get a match for all the rows in the table
MatchCollection Rows = Regex.Matches(Table.Value, RowExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Loop through each row element
foreach (Match Row in Rows) {
// Only loop through the row if it isn't a header row
if (!(iCurrentRow == 0 & HeadersExist == true)) {
// Create a new row and reset the current column counter
dr = dt.NewRow;
iCurrentColumn = 0;
// Get a match for all the columns in the row
MatchCollection Columns = Regex.Matches(Row.Value, ColumnExpression, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Loop through each column element
foreach (Match Column in Columns) {
// Add the value to the DataRow
dr(iCurrentColumn) = Column.Groups(1).ToString;
// Increase the current column
iCurrentColumn += 1;
}
// Add the DataRow to the DataTable
dt.Rows.Add(dr);
}
// Increase the current row counter
iCurrentRow += 1;
}
// Add the DataTable to the DataSet
ds.Tables.Add(dt);
}
return ds;
}
pls compile this and know me if it true and also pls check if you help..
Thanks Advance...
VulpesPosted Sep 27, 2011, 6:23 AM
Hemant KumarPosted Sep 27, 2011, 6:17 AM
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Jaganathan BantheswaranPosted Sep 27, 2011, 6:00 AM
You can use the OnLine converters like this.