copy column values from one table to another
-
Hi, I have two tables in the same dataset. What I want to do is select a row in table 1 and copy the values in some columns from table 1 to table 2. Should be easy and I think I'm making it difficult for myself with code like: DataRow[] dr = this.mycourtsDataSet1.Court1.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr["Date"] = bookingDate; nr["Court"] = "1"; if (dr.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { string test = dr[0].ItemArray.GetValue(i).ToString(); } etc ....... Any suggestions as to where I can find some help on this. TIA
Glen Harvy
-
Hi, I have two tables in the same dataset. What I want to do is select a row in table 1 and copy the values in some columns from table 1 to table 2. Should be easy and I think I'm making it difficult for myself with code like: DataRow[] dr = this.mycourtsDataSet1.Court1.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr["Date"] = bookingDate; nr["Court"] = "1"; if (dr.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { string test = dr[0].ItemArray.GetValue(i).ToString(); } etc ....... Any suggestions as to where I can find some help on this. TIA
Glen Harvy
Have you tried using BeginEdit() and EndEdit() on new row before anf after making changes?
Visit my blog at http://dotnetforeveryone.blogspot.com/
-
Have you tried using BeginEdit() and EndEdit() on new row before anf after making changes?
Visit my blog at http://dotnetforeveryone.blogspot.com/
It's making the change that I want help with, not how to save them.
Glen Harvy
-
It's making the change that I want help with, not how to save them.
Glen Harvy
Do you add the new data row in the second table?
Visit my blog at http://dotnetforeveryone.blogspot.com/
-
Do you add the new data row in the second table?
Visit my blog at http://dotnetforeveryone.blogspot.com/
DataRow[] dr2 = this.mycourtsDataSet1.Court2.Select("BookingDate = '" + bookingDate.ToShortDateString() + "'"); DataRow nr1 = this.mycourtsDataSet1.CourtSchedule.NewRow(); nr1["Date"] = bookingDate; nr1["Court"] = "2"; if (dr2.Length > 0) { for (int i = 0; i < dr[0].ItemArray.Length; i++) { if (dr2[0].Table.Columns[i].ColumnName.ToString().StartsWith("T") && !Convert.IsDBNull(dr2[0].ItemArray.GetValue(i))) { nr1[dr2[0].Table.Columns[i].ColumnName.ToString()] = Convert.ToDouble(dr2[0].ItemArray.GetValue(i)); } } } this.mycourtsDataSet1.CourtSchedule.Rows.Add(nr1); this.courtScheduleTableAdapter.Update(mycourtsDataSet1.CourtSchedule); mycourtsDataSet1.AcceptChanges();
Glen Harvy
-
It's making the change that I want help with, not how to save them.
Glen Harvy
dr.AcceptChanges();
Do your best to be the best