inserting a record after turning identity on

Hi,
The following code is part of a class in C# Windows application.
The code tries to insert a record into the distribution table. But because identity is off I have to turn it on, insert the record, and turn identity back off after the insertion is completed.

The records which is being inserted, is copied from another table called ClosedTickets.

After inserting the  copied record into the distribution table I need to delete it from the ClosedTickets table.

As you can see, I attempted to do it all in one method, which end in a syntax error near the key word "select".
This is the first time I use the identity statement.
Please correct me where I am going wrong. Thanks



  public void RestoreClosedTicket(Int32 ID)
        {
            SqlConnection con = new SqlConnection();
             con = new SqlConnection("Server=PC;;Database=SupportProject;integrated security=True");
             SqlCommand commIDentityOn = new SqlCommand("Set Identity_Insert Distribution On", con);
             SqlCommand commIdentityOff = new SqlCommand("Set Identity_Insert Distribution off", con);
             SqlCommand comm = new SqlCommand("Insert into Distribution(ID,userID,dDate,tTime,sSubject,compName,TicketContent,desDepartmwnt)Values(Select * from  ClosedTickets where ID= @ID", con);
             SqlCommand commDelete = new SqlCommand("delete from ClosedTickets where ID = @ID", con);
             comm.Parameters.AddWithValue("@ID", System.Data.SqlDbType.Int);
             comm.Parameters["@ID"].Value = ID;
             con.Open();
             commIDentityOn.ExecuteNonQuery();
             comm.ExecuteNonQuery();
             commDelete.ExecuteNonQuery();
             commIdentityOff.ExecuteNonQuery();
             con.Close();
     
         
        }
adamtraskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
When using a SELECT in an INSERT, you don't use the VALUES. Once you close out your explicit field list, simply start your SELECT.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adamtraskAuthor Commented:
Thank you.... but now I have syntax error near @ID

Here is how i rewrote the insert/select statement

  SqlCommand comm = new SqlCommand("Insert into Distribution(ID,userID,dDate,tTime,sSubject,compName,TicketContent,desDepartmwnt)(Select * from  ClosedTickets where ID= @ID", con);
0
dsackerContract ERP Admin/ConsultantCommented:
@ID probably doesn't exist. You need to concatenate that on C# style.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.