Visual Studio .NET - Insert from table to table selected line only

Asked By David on 09-Aug-11 04:50 PM
Earn up to 10 extra points for answering this tough question.
Hi All I am still stuck and getting desperate to finish or give up my project

Below is the Dataset Tableadaptor query which if you click execute the query works perfect when in Query Builder but what I am trying to do is have the option on a datagridview page to select the (Prikey3) number and run the  query with my program running this I am unable to do.
I dont know if I am trying to do it the wrong way.

INSERT INTO [COURSES PLAYED]
SELECT   COURSEName, H1PAR, H2PAR, H3PAR, H4PAR, H5PAR, H6PAR, H7PAR, H8PAR, H9PAR, H10PAR, H11PAR, H12PAR, H13PAR, H14PAR, H15PAR,
        H16PAR, H17PAR, H18PAR, H1SC, H2SC, H3SC, H4SC, H5SC, H6SC, H7SC, H8SC, H9SC, H10SC, H11SC, H12SC, H13SC, H14SC, H15SC, H16SC,
        H17SC, H18SC, H1TEE, H2TEE, H3TEE, H4TEE, H5TEE, H6TEE, H7TEE, H8TEE, H9TEE, H10TEE, H11TEE, H12TEE, H13TEE, H14TEE, H15TEE,
        H16TEE, H17TEE, H18TEE, H1FWAY, H2FWAY, H3FWAY, H4FWAY, H5FWAY, H6FWAY, H7FWAY, H8FWAY, H9FWAY, H10FWAY, H11FWAY,
        H12FWAY, H13FWAY, H14FWAY, H15FWAY, H16FWAY, H17FWAY, H18FWAY, BUNK1, BUNK2, BUNK3, BUNK4, BUNK5, BUNK6, BUNK7, BUNK8,
        BUNK9, BUNK10, BUNK11, BUNK12, BUNK13, BUNK14, BUNK15, BUNK16, BUNK17, BUNK18, PUTT1, PUTT2, PUTT3, PUTT4, PUTT5, PUTT6, PUTT7,
        PUTT8, PUTT9, PUTT10, PUTT11, PUTT12, PUTT13, PUTT14, PUTT15, PUTT16, PUTT17, PUTT18, GR1, GR2, GR3, GR4, GR5, GR6, GR7, GR8, GR9,
        GR10, GR11, GR12, GR13, GR14, GR15, GR16, GR17, GR18, BUNK1OUT, BUNK2OUT, BUNK3OUT, BUNK4OUT, BUNK5OUT, BUNK6OUT, BUNK7OUT,
        BUNK8OUT, BUNK9OUT, BUNK10OUT, BUNK11OUT, BUNK12OUT, BUNK13OUT, BUNK14OUT, BUNK15OUT, BUNK16OUT, BUNK17OUT, BUNK18OUT,
       H1YDS, H2YDS, H3YDS, H4YDS, H5YDS, H6YDS, H7YDS, H8YDS, H9YDS, H10YDS, H11YDS, H12YDS, H13YDS, H14YDS, H15YDS, H16YDS,
        H17YDS, H18YDS
FROM   COURSE
WHERE   (Prikey3 = ?)

Thanks again I appreciate your help

David
Reena Jain replied to David on 13-Aug-11 11:35 AM
hi,

use the following query to fill the data from one table to another table

  • if want to copy some fields only or fields are different of both table
Insert into Database2.Table2 (field1, field2) select field1, field2
from Database2.Table1

  • if want to copy all fields  or fields are same of both table
Insert into Database2.Table2  select * from Database2.Table1

Hope this will help you
David replied to Reena Jain on 13-Aug-11 04:47 PM
Hi Reena

The fields are the same in both tables and what I am after is how to run the query code when I run my application.
Like I said before the query runs and inserts selected line only when in query builder but I dont know how to code and run this when running the programme.

Thanks
David