VB.NET equivalent for Excel's [Data>ImportData>WebQuery]

M

MJ

Is there a VB.NET (1.1 or 2.0) equivalent for Excel's
[Data>ImportData>WebQuery]?

Below is a copy of an example of the Excel VBA that I have been using to
pull some data off a webpage. I've got a couple of simple application that
currently live in an Excel workbook as VBA solely for this one function.

I'd like to move this to a VB.NET Windows form application that does not
rely on Excel.


Example of Excel VBA:

Sub GetData()
With ActiveSheet.QueryTables.Add(Connection:="URL; _
http://www.microsoft.com", Destination:=Range("A1"))
.Name = "www.microsoft"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """nTable"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
 
M

MJ

Thanks Ken.

That seems to work, but I do have a follow-up question.

My overall objective is to get the information in a table on a webpage into
a table in a dataset.

Using the example you gave me, I modified the stringbuilder code to build a
comma-delimited string of the data I want. Save that to a text file, then
read that text file into the dataset table using
[Microsoft.VisualBasic.FileIO.TextFieldParser]

Just wondering if I'm doing this the hard way or if there is a better way.


MJ



Ken Tucker said:
Hi,

http://www.windowsformsdatagridhelp.com/default.aspx?ID=541adf13-d9c0-435c-893f-56dbb63fdf1c

Ken
------------------
MJ said:
Is there a VB.NET (1.1 or 2.0) equivalent for Excel's
[Data>ImportData>WebQuery]?

Below is a copy of an example of the Excel VBA that I have been using to
pull some data off a webpage. I've got a couple of simple application
that currently live in an Excel workbook as VBA solely for this one
function.

I'd like to move this to a VB.NET Windows form application that does not
rely on Excel.


Example of Excel VBA:

Sub GetData()
With ActiveSheet.QueryTables.Add(Connection:="URL; _
http://www.microsoft.com", Destination:=Range("A1"))
.Name = "www.microsoft"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """nTable"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
 
C

Cor Ligthert [MVP]

MJ,
Just wondering if I'm doing this the hard way or if there is a better way.
Yes that is the hard way.

In all our samples with datasets we use 3 methods.
The Northwind SQLServer sample
The Northwind Access sample database
Building direct the dataset/datatable by code

The last is in my opinion easier for you to do.

Here is a short sample, have only a look at the building in the bottom.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=76a81eb8-ea2d-48f4-99c3-a3539697edbd

There are more, however the principle is the same.
Instead of loading the row, you have to do

dt.rows.add(dt.newrow)
and than
dt.rows("fieldname1") = tagfield
etc.

There are samples about that as well on our site, however I took a short one
to show how simple it is.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top