Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:57:56+00:00 2026-05-25T09:57:56+00:00

What I am trying to do may be better for use with SQL Server

  • 0

What I am trying to do may be better for use with SQL Server but I have seen many applications in the past that simply work on text files and I am wanting to try to imitate the same behaviour that those applications follow.

I have a list of URL’s in a text file. This is simple enough to open and read line by line, but how can I store additional data from the file and query the data?

E.g.
Text File:

http://link1.com/ - 0
http://link2.com/ - 0
http://link3.com/ - 1
http://link4.com/ - 0
http://link5.com/ - 1

Then I will read the data with:

Private Sub ButtonX2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX2.Click
        OpenFileDialog1.Filter = "*txt Text Files|*.txt"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim AllText As String = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
            Dim Lines() = Split(AllText, vbCrLf)
            Dim list = New List(Of Test)
            Dim URLsLoaded As Integer = 0
            For i = 0 To UBound(Lines)
                If Lines(i) = "" Then Continue For
                Dim URLInfo As String() = Split(Lines(i), " - ")
                If URLInfo.Count < 6 Then Continue For
                list.Add(New Test(URLInfo(0), URLInfo(1)))
                URLsLoaded += 1
            Next
            DataGridViewX1.DataSource = list
            LabelX5.Text = URLsLoaded.ToString()
        End If
    End Sub

So as you can see, above I am prompting the user to open a text file, afterwards it is displayed back to the user in a datagridview.

Now here is my issue, I want to be able to query the data, E.g. Select * From URLs WHERE active=’1′ (Too used to PHP + MySQL!)

Where the 1 is the corresponding 1 or 0 after the URL in the text file.

In the above example the data is being stored in a simple class as per below:

Public Class Test
    Public Sub New(ByVal URL As String, ByVal Active As Integer)
        _URL = URL
        _Active = Active
    End Sub

    Private _URL As String
    Public Property URL() As String
        Get
            Return _URL
        End Get
        Set(ByVal value As String)
            _URL = value
        End Set
    End Property

    Private _Active As String
    Public Property Active As String
        Get
            Return _Active
        End Get
        Set(ByVal value As String)
            _Active = value
        End Set
    End Property

End Class

Am I going completely the wrong way about storing the data after importing from a text file?

I am new to VB.NET and still learning the basics but I find it much easier to learn by playing around before hitting the massive books!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:57:56+00:00Added an answer on May 25, 2026 at 9:57 am

    Working example:

    Dim myurls As New List(Of Test)
    myurls.Add(New Test("http://link1.com/", 1))
    myurls.Add(New Test("http://link2.com/", 0))
    myurls.Add(New Test("http://link3.com/", 0))
    
    Dim result = From t In myurls Where t.Active = 1
    
    For Each testitem As Test In result
        MsgBox(testitem.URL)
    Next
    

    By the way, LINQ is magic. You can shorten your loading/parse code to 3 rows of code:

    Dim Lines() = IO.File.ReadAllLines("myfile.txt")
    Dim myurls As List(Of Test) = (From t In lines Select New Test(Split(t, " - ")(0), Split(t, " - ")(1))).ToList
    DataGridViewX1.DataSource = myurls
    

    The first line reads all lines in the file to an array of strings.
    The second line splits each line in the array, and creates a test-item and then converts all those result items to an list ( of Test).

    Of course this could be misused to sillyness by making it to a one-row:er:

    DataGridViewX1.DataSource = (From t In IO.File.ReadAllLines("myfile.txt") Select New Test(Split(t, " - ")(0), Split(t, " - ")(1))).ToList
    

    Wich would render your load function to contain only following 4 rows:

    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            DataGridViewX1.DataSource = (From t In IO.File.ReadAllLines("myfile.txt") Select New Test(Split(t, " - ")(0), Split(t, " - ")(1))).ToList
            LabelX5.Text = ctype(datagridviewx1.datasource,List(Of Test)).Count
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I have an application that needs to return search results from a SQL Server
If I have a project that contains similar classes and some may use the
This may be a simple fix - but I'm trying to sum together all
This may be a bit of a nooby question, I have been trying to
I am trying to use LINQ for certain operations. So there may be chance
This may seem like a dumb topic, but I'm trying to learn some good
I'm trying to use Graphviz dot (but am willing to use something else) to
In Delphi XE, I'm trying to use GetForegroundWindow to detect the window that was
This may be a really simple question, but I'm trying to create the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.