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 770361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:29:16+00:00 2026-05-14T18:29:16+00:00

I am having problems with deleting all records in a table with VB.NET. I

  • 0

I am having problems with deleting all records in a table with VB.NET. I am using this code to delete all records in the Contacts table

        For Each contact In database.Contacts
             database.Contacts.DeleteOnSubmit(contact)
        Next

But I get this error

Can’t perform Create, Update or Delete
operations on ‘Table(Contact)’ because
it has no primary key.

Anyone have any suggestions?

  • 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-14T18:29:17+00:00Added an answer on May 14, 2026 at 6:29 pm

    You should probably have a primary key on your table. This will make working with your table much easier. If you don’t have a primary key, try finding a suitable candidate key to set as the primary key. If you have no suitable columns then you may wish to consider adding an auto incrementing surrogate key (called an identity in SQL Server). If you already have a primary key, make sure your LINQ to SQL classes are updated.

    However if you just want to delete all values you may find that this method is too slow. An alternative is to execute SQL directly using DataContext.ExecuteCommand:

    database.ExecuteCommand("DELETE Contacts");
    

    This doesn’t require that the table has a primary key. Note that this will irretrievably delete all rows in your table, so be careful. Even faster is the TRUNCATE command, but note that this requires greater privileges:

    database.ExecuteCommand("TRUNCATE TABLE Contacts");
    

    Again, be careful with this command. It will delete all rows from your table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems deleting a row using fluent nhibernate. If i execute the below
I'm having problems deleting a file from a higher directory, I found this post
Some background: I setup six blogs this week, all using Wordpress 2.92, installed with
My problem is I want to delete records from two tables, deleting the records
I'm having problems with clearing the cache of PSPDFDocument before and after deleting the
I'm having an intermittent problem deleting objects from an azure table. It only affects
I'm having a problem with T4MVC losing the code it generated each time I
I've having some problems with my eclipse set-up, and I'm thinking of just deleting
I am having a problem with deleting cookies in classic ASP. Setting and retrieving
Having problems with a small awk script, Im trying to choose the newest of

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.