Results 1 to 4 of 4

Thread: Read the data from website and sort in datagridview

  1. #1

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Read the data from website and sort in datagridview

    I need your help with this. All i need is instructions how to do this, some useful documentation links for this.

    I want to read the data from website example: http://www.livescore.com/soccer/england/premier-league/

    This Table

    Name:  4aff4ebd7cb8dcc6d9667e35e1601c61.jpg
Views: 365
Size:  59.0 KB
    To mine datagridviewin at vb.net ?

    1. Do i need to read the data as HTML code ?
    2. Is that the only way of reading content from website ?
    If yes :
    Which is the way to split the "strings" ?
    Is only way to split string using IndexOf ?
    If no:
    Which other way i need to look for ?

    Thanks to all who read this thread.

    Anel

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Read the data from website and sort in datagridview

    1. Do i need to read the data as HTML code ?
    2. Is that the only way of reading content from website ?
    If yes :
    Which is the way to split the "strings" ?
    Is only way to split string using IndexOf ?
    If no:
    Which other way i need to look for ?
    Hi, for reading data from website, you may look into WebClient or WebRequest classes from MSDN. They return the page source as HTML string. The data provided in your image is a table element. So, it's not difficult to read the contents. For splitting strings, you may use the string function Split(). Otherwise, for complex patterns, Regex is an option.

    If the website has a webservice or wcf where in you can obtain the information as XML or JSON, then that might be an option too.

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Addicted Member t3cho's Avatar
    Join Date
    Mar 2014
    Posts
    234

    Re: Read the data from website and sort in datagridview

    Thank you for your answer. I used the webclient to read the html source as string. Shown that string in textbox using this line

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim sourceString As String = New System.Net.WebClient().DownloadString("http://www.livescore.com/soccer/england/premier-league/")
            TextBox1.Text = sourceString
        End Sub
    Attachment 119003

    Now i wonder how can i "Put it to my datagridview easy" I think this is not posible with Split method because i have example :
    Code:
     <td>5</td> 
    	 <td>4</td> 
    	 <td>1</td> 
    	 <td>0</td> 
    	 <td>16</td>
    	 <td>7</td> 
    	 <td>9</td>
    Thank you once again
    Attached Images Attached Images  

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Read the data from website and sort in datagridview

    You can loop through the source and extract those values inside the td using substring or similar string functions. After you have retrieved those values/scores, put them in a List or DataTable object and then set the DataSource property of the DataGridView control with your List or DataTable.

    See setting the datasource property of datagridview here: datagridview.datasource

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width