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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MJ

    #1

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

    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.Que ryTables.Add(Co nnection:="URL; _
    http://www.microsoft.c om", Destination:=Ra nge("A1"))
    .Name = "www.micros oft"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFo rmulas = False
    .PreserveFormat ting = True
    .RefreshOnFileO pen = False
    .BackgroundQuer y = True
    .RefreshStyle = xlInsertDeleteC ells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWi dth = True
    .RefreshPeriod = 0
    .WebSelectionTy pe = xlSpecifiedTabl es
    .WebFormatting = xlWebFormatting None
    .WebTables = """nTable"" "
    .WebPreFormatte dTextToColumns = True
    .WebConsecutive DelimitersAsOne = True
    .WebSingleBlock TextImport = False
    .WebDisableDate Recognition = False
    .WebDisableRedi rections = False
    .Refresh BackgroundQuery :=False
    End With
    End Sub



  • Ken Tucker [MVP]

    #2
    Re: VB.NET equivalent for Excel's [Data>ImportD ata>WebQuery]

    Hi,



    Ken
    ------------------
    "MJ" <none@nomail.co m> wrote in message
    news:usGUQwGzFH A.908@tk2msftng p13.phx.gbl...[color=blue]
    > 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.Que ryTables.Add(Co nnection:="URL; _
    > http://www.microsoft.c om", Destination:=Ra nge("A1"))
    > .Name = "www.micros oft"
    > .FieldNames = True
    > .RowNumbers = False
    > .FillAdjacentFo rmulas = False
    > .PreserveFormat ting = True
    > .RefreshOnFileO pen = False
    > .BackgroundQuer y = True
    > .RefreshStyle = xlInsertDeleteC ells
    > .SavePassword = False
    > .SaveData = True
    > .AdjustColumnWi dth = True
    > .RefreshPeriod = 0
    > .WebSelectionTy pe = xlSpecifiedTabl es
    > .WebFormatting = xlWebFormatting None
    > .WebTables = """nTable"" "
    > .WebPreFormatte dTextToColumns = True
    > .WebConsecutive DelimitersAsOne = True
    > .WebSingleBlock TextImport = False
    > .WebDisableDate Recognition = False
    > .WebDisableRedi rections = False
    > .Refresh BackgroundQuery :=False
    > End With
    > End Sub
    >
    >
    >[/color]


    Comment

    • MJ

      #3
      Re: VB.NET equivalent for Excel's [Data&gt;ImportD ata&gt;WebQuery]

      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.Visua lBasic.FileIO.T extFieldParser]

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


      MJ



      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:OEg9x7GzFH A.2880@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi,
      >
      > http://www.windowsformsdatagridhelp....f-56dbb63fdf1c
      >
      > Ken
      > ------------------
      > "MJ" <none@nomail.co m> wrote in message
      > news:usGUQwGzFH A.908@tk2msftng p13.phx.gbl...[color=green]
      >> 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.Que ryTables.Add(Co nnection:="URL; _
      >> http://www.microsoft.c om", Destination:=Ra nge("A1"))
      >> .Name = "www.micros oft"
      >> .FieldNames = True
      >> .RowNumbers = False
      >> .FillAdjacentFo rmulas = False
      >> .PreserveFormat ting = True
      >> .RefreshOnFileO pen = False
      >> .BackgroundQuer y = True
      >> .RefreshStyle = xlInsertDeleteC ells
      >> .SavePassword = False
      >> .SaveData = True
      >> .AdjustColumnWi dth = True
      >> .RefreshPeriod = 0
      >> .WebSelectionTy pe = xlSpecifiedTabl es
      >> .WebFormatting = xlWebFormatting None
      >> .WebTables = """nTable"" "
      >> .WebPreFormatte dTextToColumns = True
      >> .WebConsecutive DelimitersAsOne = True
      >> .WebSingleBlock TextImport = False
      >> .WebDisableDate Recognition = False
      >> .WebDisableRedi rections = False
      >> .Refresh BackgroundQuery :=False
      >> End With
      >> End Sub
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Cor Ligthert [MVP]

        #4
        Re: VB.NET equivalent for Excel's [Data&gt;ImportD ata&gt;WebQuery]

        MJ,
        [color=blue]
        >
        > Just wondering if I'm doing this the hard way or if there is a better way.
        >
        >[/color]
        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.



        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("fieldn ame1") = 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


        Comment

        Working...