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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:27:31+00:00 2026-05-12T10:27:31+00:00

I have records in table1, if the records exist, it must copy into table2.

  • 0

I have records in table1, if the records exist, it must copy into table2. I want to delete those records in a table1 once all the records are copied into another table2. Im still a beginner in database and with some researches, i found some tutorials on d internet how to connect with database, and the codes easy to understand so i came out with this program.This codes only do the copy part and i’m still lack of the delete part. Can help me figure out how to do the delete part? i found 2 reference in msdn, but i’m not sure and not understand on the codes given.

 
try
{
 //create connection
 System.Data.SqlClient.SqlConnection sqlConnection1 =
    new System.Data.SqlClient.SqlConnection("Data Source=.dbname;Integrated Security=True;User Instance=True");
 //command queries
 System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
 cmd.CommandType = System.Data.CommandType.Text;
 cmd.CommandText = "INSERT INTO tblSend (ip, msg, date) SELECT ip, msg, date FROM tblOutbox";
 cmd.Connection = sqlConnection1;
 sqlConnection1.Open(); //open con
 cmd.ExecuteNonQuery(); //execute query
 sqlConnection1.Close(); //close con
}
catch (System.Exception excep)
{
  MessageBox.Show(excep.Message);
}

If i replace the query into this: //cmd.CommandText = "DELETE tblSend WHERE id = 5";
its only delete one rows. But what if many records involved? Do i need to consider the EOF things? DO i need to use DataGridView? Becoz the code i did didn't use DataGridView at all. i dont want the records to be displayed, i just want it to running behind.

  • 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-12T10:27:32+00:00Added an answer on May 12, 2026 at 10:27 am

    If I understand correctly you need all data from table1 in table2 and then delete table1.

    Options

    1) It you need it once you could rename table1 to table2 and recreate table1

    -- move the records to table 2, ok I assume it does not exist;)
    RENAME TABLE table1 TO table2;
    -- Create new table1 with same structure as table 2
    CREATE TABLE table1 AS SELECT * FROM table2 WHERE 1=2;
    

    2) Do a separate copy and delete assuming you have something like a primary key

    -- copy the records
    INSERT table2(field1, field2, ...) SELECT field1, field2, ... FROM table1;
    -- and delete them 
    DELETE FROM table1;
    

    3) Do it using C# but as this seems a database problem to me I would not go that far in pulling all the records to the client and then throwing them back.

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

Sidebar

Related Questions

consider the following example. I have to select all the records from table1 which
I have two tables table1 = records, table2 = duplicates. Both tables contain a
I have the correlated subquery below. Each id (147,148,149) in table1 has many records
I have one table that has sales records and another table that has additional
I have two tables table1 and table2. Table1 is generated by a parser and
I want to have a stored procedure that inserts a record into tableA and
Possible Duplicate: SQL - find records from one table which don't exist in another
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London
Anyone have sugestion or example on how displaying Google Datastore records table with pagination
I have 11 records in the Menu table, only 1 with a PageID set

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.