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

  • Home
  • SEARCH
  • 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 800179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:15:08+00:00 2026-05-14T23:15:08+00:00

I’m working on a little side app for a client whereby they provide me

  • 0

I’m working on a little side app for a client whereby they provide me with a list of cities and I have to insert them into the database and associate them with their parent records.

Example:

ID   |   PID   |   Region
1         0         California
2         1         Los Angeles
3         1         San Fransisco

Now my code looks like this

    Dim input As StreamReader
    Dim index As Integer
    Dim filename As String
    Dim RegionDC As New DAL.RegionsDataContext



    For Each TextFile As String In Directory.GetFiles(Server.MapPath("~/app_data/business-trader cities/"))
        input = File.OpenText(TextFile)
        filename = New FileInfo(TextFile).Name
        index = 0


        ''# this is where we want to select the ID for the filename'
        Dim _ID = (From R In RegionDC.bt_Regions _
                 Where R.Region = filename.Replace(".txt", "") _
                 Select R.ID).FirstOrDefault

        While Not input.EndOfStream

            Dim q = (From r In RegionDC.bt_Regions _
                     Where r.Region = input.ReadLine() _
                     Select r.ID).FirstOrDefault

            ''# ***********************************'
            ''#  HERE IS WHERE IM TRYING TO VERIFY'
            ''#  IF THE RECORD EXISTS OR NOT'
            ''# ***********************************'

            ''# now we loop through the txt file'
            ''# and insert the data into the database'
            Dim oRegion As New DAL.bt_Region
            oRegion.Region = input.ReadLine()
            oRegion.FSSearchCount = 0
            oRegion.WSearchCount = 0
            oRegion.PID = _ID

            RegionDC.bt_Regions.InsertOnSubmit(oRegion)
            RegionDC.SubmitChanges()

        End While

        ''# clean up the locked files'
        input.Close()
        input.Dispose()
    Next

So basically if Los Angeles is in the TXT file, I don’t want it re-entered into the database since it already exists.

Can anyone help me figure out how to verify if a record already exists prior to inserting?

  • 1 1 Answer
  • 2 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-14T23:15:09+00:00Added an answer on May 14, 2026 at 11:15 pm

    LINQ To SQL Samples – EXISTS/IN/ANY/ALL

    Public Sub LinqToSqlExists01()
        Dim q = From c In db.Customers _
                Where Not c.Orders.Any()
    
        ObjectDumper.Write(q)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am using Paperclip to handle profile photo uploads in my app. They upload
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.