Silverlight / WPF - Call and run insert command

Asked By David on 02-Aug-11 04:51 PM
 I am asking again for help to finish my project I started 18 months ago when I retired and still have no clue how to  finish it No one seems to be able to help and after all the months I have toiled to try and finish it but am getting nowhere There must be some body that can tell if what I am asking is possible or am I trying to do it the wrong way.
 
I want to call and run the insert command from a dataset which selects a row from Table 1 and insert this row into table 2.
I am using a datagrid view to select the row
It works perfect in manual design mode but I have no Idea how to apply code etc

Private Sub BindingNavigatorAddNewItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click


'What goes in here to call and run a Dataset-Tableadapter-insert command to


'select a row from a Datagridview-form and run the insert-command to put

'that row into Table2

' I am lost completely as what to do!!!




Me.taManager.UpdateAll(Me.CoursesPlayedDataSet)

CoursesPlayedDataSet.AcceptChanges()


End Sub

 Thanks David
Please rescue me if you can

pete rainbow replied to David on 02-Aug-11 08:20 PM
it's not clear if you need this to be done in the client tier

would it not be possible to just do this in a simple sql statement or stored proc, if all the gui is doing is showing whats in the dbms

then would be something like

SELECT t1.field1, etc etc
INTO table2 t2
FROM tabel1 t1
where t1.field1 = etc etc
David replied to pete rainbow on 03-Aug-11 03:17 AM
 Hi Pete
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
Radhika roy replied to David on 03-Aug-11 11:44 AM
As you told that you want to get data from Table1 and after that you want to add in table2.

for that follow these steps-



1. Get data from database and fill to ds1

2. after that use loop to get all rows of table1 using ds1.

3. inside loop add row to the ds2.

4. assign values to the ds2.

5. finally update ds2.


like this-

int i=0;

 foreach(DataRow r in ds1.Tables[0].Rows)
  {
   ds2.Tables[0].Rows[i][0]=r[0];
   ds2.Tables[0].Rows[i][1]=r[1];

   i++;
  }


//Finally Update the Ds2

Hope this will help you.
David replied to Radhika roy on 04-Aug-11 04:30 PM
 Hi Radhika
 Sorry but the code etc does not mean anything to me its done in visual studio 2008 and the code has no { } it dont like them .
Thanks

David