?
Solved

Programmatically clear the data from a SQL Server 2005 table in VB.NET

Posted on 2008-11-17
5
Medium Priority
?
657 Views
Last Modified: 2012-05-05
I want to clear all the data from an SQL Server 2005 table with a Visual Studio 2008 VBasic program. Currently I am looping througn the table deleting each row. I thought there may be a way to do this in one hit
0
Comment
Question by:milkwood
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Ernariash earned 1000 total points
ID: 22980743

---Run script.
Delete From yourtable
--or faster
Truncate Table YourTable
0
 

Author Comment

by:milkwood
ID: 22980864
How do you do that from within VB.net?
0
 
LVL 15

Assisted Solution

by:JackOfPH
JackOfPH earned 1000 total points
ID: 22981363
Dim con As New SqlClient.SqlConnection("Your connection string here")
        con.Open()
        Dim cmd As New SqlClient.SqlCommand("Delete * from YourTable", con)

        cmd.ExecuteNonQuery()

        cmd.Dispose()
        cmd = Nothing
        con.Close()
        con.Dispose()
        con = Nothing
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 22981558
For connection strings:

Visit this site:
http://www.connectionstrings.com/
0
 

Author Closing Comment

by:milkwood
ID: 31517683
Thanks, in fairness I have split the points as I used a bit from both. The "TRUNCATE TABLE" was much faster and the VB.net code worked fine
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question