From Gustav at cactus.dk Fri Feb 1 12:49:54 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 01 Feb 2008 19:49:54 +0100 Subject: [dba-VB] Browsing records (was: Renaming DBA-VB) Message-ID: Hi all I just found out how ...: - click the top-right tiny arrow of the BindingNavigator. The BindingNavigator Tasks pane pops up - click the top item in this, "Embed in ToolStripContainer" A ToolStripContainer is created. Adjust the size of this or choose to dock it in the parent. Now the BindingNavigator can be moved around inside the ToolStripContainer. /gustav >>> Gustav at cactus.dk 25-10-2007 14:03:08 >>> Hi William Which control do you use for browsing records on forms? The default dataTableBindingNavigator? If so, have you managed to undock it so it can float? I have the GripStyle set to Visible, but the toolstrip is not to grip and move around. /gustav >>> wdhindman at dejpolsystems.com 25-10-2007 10:24 >>> Shamil ...yes, free!!! ...the express products value has been simply incredible for me ...I've yet to run into anything I could do with Access that I can't find a way to do with one or more of the express products ...and the amount/quality of code/support available on-line is every bit as good ...I still tend to model an app in Access first but I'm now starting to deliver in VS/SQL Server ...and the client sales are soooooo much easier in most cases. William ----- Original Message ----- From: "Shamil Salakhetdinov" To: Sent: Thursday, October 25, 2007 2:48 AM Subject: Re: [dba-VB] Renaming DBA-VB > <<< > I was unaware of the product cost.... >>>> > Hi Jim. > > Yes, I have just checked the price - it looks unaffordable for > small-/middle-size businesses. Yes, there is evaluation version but... > > I'd currently think that ASP.NET and C#/VB.NET(VS Express) + MS SQL 2005 > Express/Access backend DB is the best ever available toolset for Web (and > whatever else) real life business applications development... > > And they are free for download and use, aren't they?... > > > -- > Shamil > > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Thursday, October 25, 2007 5:46 AM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I do not usually answer my own emails but... > > I must qualify my last comments as I was unaware of the product cost which > had me fumbling for my oxygen mask as soon as I saw it. > > Fortunately there are evaluation copies available. > > Jim > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Wednesday, October 24, 2007 12:12 PM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I offer wonder why Ruby-on-rails is such a popular program considering > that > its performance is rated at one thirtieth of that of C and far below the > speed of any .Net flavour. > > A friend has recently been required to work with ROR and was not impressed > with performance and that it could be written so cryptic that he was > required to write extensive notes in the code. > > His recommendation for the finest .Net programming language is Eiffel: > http://archive.eiffel.com/doc/manuals/technology/dotnet/eiffelsharp/ > > Jim From pete.phillipps at ntlworld.com Sun Feb 3 15:00:26 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Sun, 3 Feb 2008 21:00:26 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com> <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> Message-ID: Hi Everyone, In VB6, the following code sets/unsets the text box to bold and/italic depending on the value of the checkboxes: txtMyText.Font.Bold = chkBold.Value txtMyText.Font.Italic = chkItalic.Value How do you do the same in VB2005? Pete From stuart at lexacorp.com.pg Sun Feb 3 17:42:31 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Mon, 04 Feb 2008 09:42:31 +1000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, Message-ID: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> On 3 Feb 2008 at 21:00, Pete Phillipps wrote: > In VB6, the following code sets/unsets the text box to bold > and/italic depending on the value of the checkboxes: > txtMyText.Font.Bold = chkBold.Value > txtMyText.Font.Italic = chkItalic.Value > > How do you do the same in VB2005? > Private Sub chkBoxes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged, chkItalic.CheckedChanged Dim intFontAttribs As Integer intFontAttribs = IIf(chkBold.Checked, FontStyle.Bold, 0) + IIf(chkItalic.Checked, FontStyle.Italic, 0) txtmyText.Font = New Font(txtmyText.Font, intFontAttribs) End Sub From Gustav at cactus.dk Mon Feb 4 11:41:29 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Mon, 04 Feb 2008 18:41:29 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi all I have created two tableadapters, a source and a target, and need to browse through the source looking for rows and, when a row meeting some conditions is found, copy this to the target. What is the best method? /gustav From pete.phillipps at ntlworld.com Mon Feb 4 12:40:52 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Mon, 4 Feb 2008 18:40:52 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> Message-ID: Hi Stuart, <> Thanks, it's so simple when you know what you're doing :-) Pete "Many [wargame] battles have been fought and won by soldiers nourished on beer" - Frederick the Great, 1777 Download VIEW FROM THE TRENCHES (Britain's Premier ASL Journal) free from http://www.vftt.co.uk Get the latest news about HEROES(ASL in Blackpool) at http://www.vftt.co.uk/heroesdetails.asp Get the latest news about INTENSIVE FIRE (Britain's biggest ASL tournament) at http://www.vftt.co.uk/ifdetails.asp Get the latest UK ASL Tournament news at http://www.asltourneys.co.uk Support the best at http://www.manutd.com/ From stuart at lexacorp.com.pg Mon Feb 4 17:06:55 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Tue, 05 Feb 2008 09:06:55 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A8272F.14339.53AB50B@stuart.lexacorp.com.pg> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From Gustav at cactus.dk Tue Feb 5 11:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 05 Feb 2008 18:02:16 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Tue Feb 5 17:11:40 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Wed, 06 Feb 2008 09:11:40 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A979CC.20571.A656998@stuart.lexacorp.com.pg> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From michael at ddisolutions.com.au Tue Feb 5 22:21:02 2008 From: michael at ddisolutions.com.au (Michael Maddison) Date: Wed, 6 Feb 2008 15:21:02 +1100 Subject: [dba-VB] Emailing: time_detail.rpt References: <59A61174B1F5B54B97FD4ADDE71E7D013BF274@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39353@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF275@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3936A@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF277@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39390@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF279@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E393C0@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF27B@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3944F@ssyd2800.rcl.domain> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D013BF27E@ddi-01.DDI.local> Hi Col and Denice, The final version of the time detail report is in place. I had to use the 'unscheduled' attribute to identify the OT. So any unscheduled OT will show in the ADJ/ENT column only. Let me know if there are any problems. FYI We are moving offices tomorrow and we cant be sure when Telstra will have the new phone lines ready or when our internet connection will be available. It is probably a good idea to catch me on the mobile till it gets sorted out. regards Michael Maddison DDI Solutions Pty Ltd michael at ddisolutions.com.au Bus: 0260400620 Mob: 0412620497 www.ddisolutions.com.au This Email message is for the sole use of the intended recipient and may contain confidential and privileged information. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply Email and destroy all copies as well as the original message. All views expressed in this Email are those of the sender, except where specifically stated otherwise, and do not necessarily reflect the views of DDi Solutions. From Gustav at cactus.dk Wed Feb 6 02:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 09:16:09 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart That is what I imagined initially. Problem is, however and to my surprise, that neither a DataSet nor a DataTable features an Update method. So what to do? I can't believe you have to revert to pure SQL commands to write back an update of a DataSet or DataTable?? /gustav >>> stuart at lexacorp.com.pg 06-02-2008 00:11 >>> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From Gustav at cactus.dk Wed Feb 6 07:30:02 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 14:30:02 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. In my code sample below, I marked rows as Modified with method SetModified. The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. For a row to be inserted by the later Update call, it has to have RowState set to Added. So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: // Mark row as modified. kundeRowS.SetModified(); or: // Mark row as new. kundeRowS.SetAdded(); When I changed the code from SetModified to SetAdded and replaced the Fill method with: kundeAdapterT.Update(kunderT); all records were written to the target table. Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: kunderT.Rows.Add(rowToAdd); RowState of those rows, I guess, will be switched to Added automatically. /gustav >>> Gustav at cactus.dk 05-02-2008 18:02 >>> Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Wed Feb 6 17:13:56 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Thu, 07 Feb 2008 09:13:56 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From cfoust at infostatsystems.com Wed Feb 6 19:25:32 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 6 Feb 2008 17:25:32 -0800 Subject: [dba-VB] Copy tables In-Reply-To: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> References: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Message-ID: I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 05:35:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 12:35:32 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_with_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From cfoust at infostatsystems.com Thu Feb 7 10:31:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 08:31:25 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_wit h_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a > button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 10:59:30 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 17:59:30 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 11:51:14 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 09:51:14 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: It clears the DataRow collection of the datatable. Charlotte -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 12:07:54 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 10:07:54 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 17:00:56 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 00:00:56 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 19:16:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 17:16:26 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 8 01:58:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 08:58:14 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks for that explanation, I can see why you do it this way. My situation is somewhat different as no data will be live - the source is an Access mdb permanently linked to the SQL Server - and the import will be run at regular intervals. Thus, should a row or two be lost during an import they will be fetched at the next run. As for the array compare, I will check out your idea of a temp table. /gustav >>> cfoust at infostatsystems.com 08-02-2008 02:16 >>> I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From Gustav at cactus.dk Fri Feb 8 10:41:39 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 17:41:39 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart et al The hash code of a row cannot be used as it is based on the parent (name of DateTable or DataSet object) and the position of the row in this, not the content. And ToString of the ItemArray and other objects just returns the name of the object, not the content or value of it. However, I located a very simple method to compare two arrays with "normal" content - not BLOBS or binaries - without having to code loops and so on. Once again, the .Net framework came to rescue - this time with Concat which (also) is able to concatenate the rows of an array. So: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableOrdreTableAdapter ordreSAdapter = new VrsSourceTableAdapters.DataTableOrdreTableAdapter(); VrsSource.DataTableOrdreDataTable ordreS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableOrdreTableAdapter ordreTAdapter = new VrsTargetTableAdapters.DataTableOrdreTableAdapter(); VrsTarget.DataTableOrdreDataTable ordreT; // DataTable for source. ordreS = ordreSAdapter.GetDataVrsOrdrer(); // DataTable for target. ordreT = ordreTAdapter.GetDataVrsOrdrer(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableOrdreRow foundRow = null; // Variables to hold hash codes of row contents. int hashSource; int hashTarget; foreach (VrsSource.DataTableOrdreRow ordreSRow in ordreS) { // Value of primary key to locate. key = ordreSRow.ordreNr; // Find a matching row in the target. foundRow = ordreT.FindByOrdreNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. ordreSRow.SetAdded(); // Append it to the target preserving the RowState. ordreT.ImportRow(ordreSRow); } else { // Row is found. Console.WriteLine(" Found: " + key.ToString()); // Calculate hash code to see if source row and target row match. hashSource = String.Concat(ordreSRow.ItemArray).GetHashCode(); hashTarget = String.Concat(foundRow.ItemArray).GetHashCode(); Console.WriteLine(" - Hash: " + hashSource.ToString() + " - " + hashTarget.ToString()); if (hashSource != hashTarget) { // The source row is updated. Console.WriteLine(" Modified OrdreNr: " + ordreSRow.ordreNr + ""); // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = ordreSRow.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } } // Write back to the database table the updated/appended rows of target DataTable. ordreTAdapter.Update(ordreT); Of course, if you have juxtaposed columns with similar content like: Val1 Val2 Concatenated string 3 44 344 34 4 344 just concatenating these may in some cases fail as the right column shows, but that is not the case for my current task. So now I only update modified records and append new records leaving the bunch of not modified records untouched! /gustav >>> Gustav at cactus.dk 08-02-2008 00:00 >>> Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From askolits at nni.com Fri Feb 8 15:35:40 2008 From: askolits at nni.com (John Skolits) Date: Fri, 8 Feb 2008 16:35:40 -0500 Subject: [dba-VB] VBA Excel Validation Message-ID: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits From shamil at users.mns.ru Sat Feb 9 04:26:38 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 13:26:38 +0300 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> Message-ID: <000f01c86b06$40ef9cc0$6401a8c0@nant> Hello John, Excel.Worksheet object has several events related to Excel.Range: Event Change(Target As Range) Event SelectionChange(Target As Range) Event BeforeDoubleClick(Target As Range, Cancel As Boolean) Event BeforeRightClick(Target As Range, Cancel As Boolean) You can try to explore and use these events... Excel.Workbook object has a couple of useful events to implement validation on whole worksheet/workbook level: Event BeforeSave(SaveAsUI As Boolean, Cancel As Boolean) Event BeforeClose(Cancel As Boolean) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 12:36 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] VBA Excel Validation This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From askolits at nni.com Sat Feb 9 09:25:35 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:25:35 -0500 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <001501c86b30$04e11040$0202fea9@LaptopXP> Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub From ssharkins at gmail.com Sat Feb 9 09:26:33 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Sat, 9 Feb 2008 10:26:33 -0500 Subject: [dba-VB] VBA Excel Validation References: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? From askolits at nni.com Sat Feb 9 09:33:34 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:33:34 -0500 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001501c86b30$04e11040$0202fea9@LaptopXP> Message-ID: <001601c86b31$229af7d0$0202fea9@LaptopXP> It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Sat Feb 9 10:20:27 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 19:20:27 +0300 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001601c86b31$229af7d0$0202fea9@LaptopXP> Message-ID: <000001c86b37$ae6f1d30$6401a8c0@nant> Congrats! :) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 6:34 PM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] RRESOVED! E: VBA Excel Validation It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Feb 10 04:18:26 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:18:26 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 04:25:18 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:25:18 +0100 Subject: [dba-VB] Installing SQL Server 2005 Management Studio after Visual Studio 2008 Message-ID: Hi all Found this tip which can save you a lot of time and lost hair: http://codingreflection.com/wordpress/?p=371 should you receive the message: "None of the selected features can be installed or upgraded." If so, use this command to run the install where d is your cd drive: d:\setup.exe SKUUPGRADE=1 /gustav From Gustav at cactus.dk Sun Feb 10 08:09:12 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 15:09:12 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi all Well, they (MS) are not kidding: http://blogs.msdn.com/somasegar/archive/2007/12/09/visual-studio-and-sql-server-2008.aspx For Visual Studio 2008 to support SQL Server 2008, we will be delivering a patch to coincide with the next CTP of SQL Server 2008. which raises the logical question: When is next CTP of SQL Server 2008 coming out? ... Monday, January 21, 2008 1:53 PM by Somasegar The next CTP of SQL Server 2008 will likely come out towards the end of Feburary - in time for the "VS2008, Windows Server 2008 and SQL Server 2008" launch. Good timing? /gustav >>> Gustav at cactus.dk 10-02-2008 11:18 >>> Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 11:14:00 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 18:14:00 +0100 Subject: [dba-VB] Visual Studio 2008: MSDTC on server 'servername' is unavailable (Solution) Message-ID: Hi all When you try to connect to a linked database on a remote server, you will probably succeed. However, when you try to preview the data (using the GetData.. method), you may receive this message just as data are to be retrieved: MSDTC on server 'servername' is unavailable I found the solution here: http://geekswithblogs.net/narent/archive/2006/10/09/93544.aspx Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Run MS DTC If you have the application and the SQL Server Data base in two different machines you must do that also Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Properties > MS DTC (TAB) > allow remote access In my case, the MS DTC service was running - I just had to touch it as described to get it working. Somewhat strange, I think, but who cares. Also, I modified the hosts and lmhosts.sam files to include the name lookup of the remote server as this is not a server with a public URL, but I'm not sure if that really is necessary as VS previously was perfectly able to preview a table of a normal database (but not of a linked) on that same server. hosts file: xxx.xxx.xxx.xxx servername # Description of server lmhosts.sam file: xxx.xxx.xxx.xxx servername #PRE #Description of server /gustav From accessd at shaw.ca Sun Feb 10 12:33:23 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sun, 10 Feb 2008 10:33:23 -0800 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP In-Reply-To: References: Message-ID: Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; Hi Jim True, but indeed I suspect this issue to be true also if the SQL Server 2008 is installed on a remote machine. VS2008 seems to have very few issues running on Vista Business which is what I use. /gustav >>> accessd at shaw.ca 10-02-2008 19:33 >>> Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; References: <000f01c86b06$40ef9cc0$6401a8c0@nant> <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Message-ID: <020e01c86c2f$1d233b10$0f01a8c0@officexp> Thanks for getting back to me. I ended up using one of the events to do a validation. But I may use your recommendation for something else. Thanks, John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Saturday, February 09, 2008 10:27 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VBA Excel Validation Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From accessd at shaw.ca Sat Feb 16 13:52:51 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sat, 16 Feb 2008 11:52:51 -0800 Subject: [dba-VB] New Library on the DBA site In-Reply-To: <003d01c870a3$a11e3230$4b3a8343@SusanOne> References: <001201c8709f$b7bb5e40$0300a8c0@danwaters> <003d01c870a3$a11e3230$4b3a8343@SusanOne> Message-ID: Hi All: There is a new Library section added to the DBA (http://www.databaseadvisors.com) web site. The section is split into 3 modules, one for books, one for articles and one for Podcast. This section is designed to high-lite the creations of list members. The present pages are by no means current or complete and are but a sample of what our members have created. If you have more links and contribution please email me, Jim Lawrence at webmaster at databaseadvisors.com Regards Jim From fhtapia at gmail.com Mon Feb 18 17:28:55 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 18 Feb 2008 15:28:55 -0800 Subject: [dba-VB] Building something quick 'n dirty Message-ID: I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From Gustav at cactus.dk Tue Feb 19 01:26:19 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 19 Feb 2008 08:26:19 +0100 Subject: [dba-VB] Building something quick 'n dirty Message-ID: Hi Francisco Given that time frame, CodeCharge comes to my mind: http://www.yessoftware.com/index2.php /gustav >>> fhtapia at gmail.com 19-02-2008 00:28 >>> I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From dwaters at usinternet.com Tue Feb 19 14:59:21 2008 From: dwaters at usinternet.com (Dan Waters) Date: Tue, 19 Feb 2008 14:59:21 -0600 Subject: [dba-VB] Any Students Out There? Message-ID: <004601c8733a$4ce7dba0$0300a8c0@danwaters> >From USA Today: Microsoft is giving students free access to its most sophisticated tools for writing software and making media-rich websites, a move that intensifies its competition with Adobe Systems and could challenge open source software's popularity. The Redmond-based software maker said late Monday it will let students download Visual Studio Professional Edition, a software development environment; Expression Studio, which includes graphic design and website and hybrid Web-desktop programming tools; and XNA Game Studio 2.0, a video game development program. From Gustav at cactus.dk Wed Feb 20 13:38:50 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 20 Feb 2008 20:38:50 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From Gustav at cactus.dk Thu Feb 21 06:33:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 21 Feb 2008 13:33:41 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From accessd at shaw.ca Thu Feb 21 14:52:57 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 21 Feb 2008 12:52:57 -0800 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? In-Reply-To: References: Message-ID: <0FF1B8B3E7B040B88549BFEE9E780C48@creativesystemdesigns.com> Hi Gustav: That is a helpful piece of information. Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 4:34 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 01:35:36 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 08:35:36 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From cfoust at infostatsystems.com Fri Feb 22 09:49:30 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 22 Feb 2008 07:49:30 -0800 Subject: [dba-VB] DataSet, view deleted rows In-Reply-To: References: Message-ID: You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 10:04:48 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 17:04:48 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi Charlotte That is of course more direct for single values. So much to learn ... /gustav >>> cfoust at infostatsystems.com 22-02-2008 16:49 >>> You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From Gustav at cactus.dk Wed Feb 27 08:18:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 15:18:41 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Johncliviger at aol.com Wed Feb 27 10:39:25 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 11:39:25 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: How about the app.config in the solution explorer johnc From Gustav at cactus.dk Wed Feb 27 11:15:58 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:15:58 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Well, that is what I thought. But it is read-only. Has to be edited manually via the GUI. /gustav >>> Johncliviger at aol.com 27-02-2008 17:39 >>> How about the app.config in the solution explorer johnc From Johncliviger at aol.com Wed Feb 27 11:50:59 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 12:50:59 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Wed Feb 27 11:54:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:54:47 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Yes, just use my normal address: gustav at cactus.dk /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Thu Feb 28 04:00:21 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 11:00:21 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Johncliviger at aol.com Thu Feb 28 04:50:46 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Thu, 28 Feb 2008 05:50:46 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Gustav mmmm...not sure I've got an answer....let me poke around in some other stuff I've got. johnc From BarbaraRyan at cox.net Thu Feb 28 06:13:09 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:13:09 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: Message-ID: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From BarbaraRyan at cox.net Thu Feb 28 06:49:25 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:49:25 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> Message-ID: <012701c87a08$593b88a0$0a00a8c0@PCRURI35> Sorry... I just realized that this is the VB mail list...Barb -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Barbara Ryan Sent: Thursday, February 28, 2008 7:13 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VS2005: Storing application settings I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Thu Feb 28 10:01:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 08:01:26 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Thu Feb 28 11:02:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 18:02:08 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From cfoust at infostatsystems.com Thu Feb 28 11:28:37 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 09:28:37 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 29 07:22:06 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:22:06 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte et al OK, I'm a child of VS2005, and when creating data sources the wizard kindly asks if you wish to save the connection strings in a file. Yes please, and that file happens to be app.config which you can read and write via the GUI. Now I realize that this file has entries for application settings as well as user settings where the main difference is that the application settings are read-only during runtime. This, of course, limits the value of using the application settings as you may have a need to store or edit application setting entries during runtime. I don't like to reinvent the wheel so I wondered if any method exists to circumvent this limitation other than to create a separate system as you have done. The only method I have seen is to open the app.config XML file directly as any other XML file: http://www.ryanfarley.com/blog/archive/2004/07/13/879.aspx To complicate matters, an advice is _not_ to do that because - as I mentioned previously - if the app.config file is read-only, it might be for a reason. That reason is explained here: http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav >>> cfoust at infostatsystems.com 28-02-2008 18:28 >>> OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Fri Feb 29 07:58:40 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:58:40 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From cfoust at infostatsystems.com Fri Feb 29 10:00:48 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 08:00:48 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From ssharkins at gmail.com Fri Feb 29 10:40:48 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 11:40:48 -0500 Subject: [dba-VB] VS2005: Storing application settings References: Message-ID: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, but > I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From cfoust at infostatsystems.com Fri Feb 29 11:29:51 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 09:29:51 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: Storing stuff in the registry is definitely discouraged in dotNet, Susan. And more and more, the registry is being locked down by system administrator. We started to run into problems with that in our extant Access applications. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Friday, February 29, 2008 8:41 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VS2005: Storing application settings > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, > but I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From Gustav at cactus.dk Fri Feb 29 11:31:04 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 18:31:04 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte Thanks. I'll stick to that method. /gustav >>> cfoust at infostatsystems.com 29-02-2008 17:00 >>> I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From ssharkins at gmail.com Fri Feb 29 11:47:20 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 12:47:20 -0500 Subject: [dba-VB] VS2005: Storing application settings References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: <013201c87afb$31a5d270$4b3a8343@SusanOne> Too bad... it's an easy solution. Susan H. > Storing stuff in the registry is definitely discouraged in dotNet, > Susan. And more and more, the registry is being locked down by system > administrator. We started to run into problems with that in our extant > Access applications. From Gustav at cactus.dk Fri Feb 1 12:49:54 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 01 Feb 2008 19:49:54 +0100 Subject: [dba-VB] Browsing records (was: Renaming DBA-VB) Message-ID: Hi all I just found out how ...: - click the top-right tiny arrow of the BindingNavigator. The BindingNavigator Tasks pane pops up - click the top item in this, "Embed in ToolStripContainer" A ToolStripContainer is created. Adjust the size of this or choose to dock it in the parent. Now the BindingNavigator can be moved around inside the ToolStripContainer. /gustav >>> Gustav at cactus.dk 25-10-2007 14:03:08 >>> Hi William Which control do you use for browsing records on forms? The default dataTableBindingNavigator? If so, have you managed to undock it so it can float? I have the GripStyle set to Visible, but the toolstrip is not to grip and move around. /gustav >>> wdhindman at dejpolsystems.com 25-10-2007 10:24 >>> Shamil ...yes, free!!! ...the express products value has been simply incredible for me ...I've yet to run into anything I could do with Access that I can't find a way to do with one or more of the express products ...and the amount/quality of code/support available on-line is every bit as good ...I still tend to model an app in Access first but I'm now starting to deliver in VS/SQL Server ...and the client sales are soooooo much easier in most cases. William ----- Original Message ----- From: "Shamil Salakhetdinov" To: Sent: Thursday, October 25, 2007 2:48 AM Subject: Re: [dba-VB] Renaming DBA-VB > <<< > I was unaware of the product cost.... >>>> > Hi Jim. > > Yes, I have just checked the price - it looks unaffordable for > small-/middle-size businesses. Yes, there is evaluation version but... > > I'd currently think that ASP.NET and C#/VB.NET(VS Express) + MS SQL 2005 > Express/Access backend DB is the best ever available toolset for Web (and > whatever else) real life business applications development... > > And they are free for download and use, aren't they?... > > > -- > Shamil > > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Thursday, October 25, 2007 5:46 AM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I do not usually answer my own emails but... > > I must qualify my last comments as I was unaware of the product cost which > had me fumbling for my oxygen mask as soon as I saw it. > > Fortunately there are evaluation copies available. > > Jim > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Wednesday, October 24, 2007 12:12 PM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I offer wonder why Ruby-on-rails is such a popular program considering > that > its performance is rated at one thirtieth of that of C and far below the > speed of any .Net flavour. > > A friend has recently been required to work with ROR and was not impressed > with performance and that it could be written so cryptic that he was > required to write extensive notes in the code. > > His recommendation for the finest .Net programming language is Eiffel: > http://archive.eiffel.com/doc/manuals/technology/dotnet/eiffelsharp/ > > Jim From pete.phillipps at ntlworld.com Sun Feb 3 15:00:26 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Sun, 3 Feb 2008 21:00:26 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com> <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> Message-ID: Hi Everyone, In VB6, the following code sets/unsets the text box to bold and/italic depending on the value of the checkboxes: txtMyText.Font.Bold = chkBold.Value txtMyText.Font.Italic = chkItalic.Value How do you do the same in VB2005? Pete From stuart at lexacorp.com.pg Sun Feb 3 17:42:31 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Mon, 04 Feb 2008 09:42:31 +1000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, Message-ID: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> On 3 Feb 2008 at 21:00, Pete Phillipps wrote: > In VB6, the following code sets/unsets the text box to bold > and/italic depending on the value of the checkboxes: > txtMyText.Font.Bold = chkBold.Value > txtMyText.Font.Italic = chkItalic.Value > > How do you do the same in VB2005? > Private Sub chkBoxes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged, chkItalic.CheckedChanged Dim intFontAttribs As Integer intFontAttribs = IIf(chkBold.Checked, FontStyle.Bold, 0) + IIf(chkItalic.Checked, FontStyle.Italic, 0) txtmyText.Font = New Font(txtmyText.Font, intFontAttribs) End Sub From Gustav at cactus.dk Mon Feb 4 11:41:29 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Mon, 04 Feb 2008 18:41:29 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi all I have created two tableadapters, a source and a target, and need to browse through the source looking for rows and, when a row meeting some conditions is found, copy this to the target. What is the best method? /gustav From pete.phillipps at ntlworld.com Mon Feb 4 12:40:52 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Mon, 4 Feb 2008 18:40:52 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> Message-ID: Hi Stuart, <> Thanks, it's so simple when you know what you're doing :-) Pete "Many [wargame] battles have been fought and won by soldiers nourished on beer" - Frederick the Great, 1777 Download VIEW FROM THE TRENCHES (Britain's Premier ASL Journal) free from http://www.vftt.co.uk Get the latest news about HEROES(ASL in Blackpool) at http://www.vftt.co.uk/heroesdetails.asp Get the latest news about INTENSIVE FIRE (Britain's biggest ASL tournament) at http://www.vftt.co.uk/ifdetails.asp Get the latest UK ASL Tournament news at http://www.asltourneys.co.uk Support the best at http://www.manutd.com/ From stuart at lexacorp.com.pg Mon Feb 4 17:06:55 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Tue, 05 Feb 2008 09:06:55 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A8272F.14339.53AB50B@stuart.lexacorp.com.pg> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From Gustav at cactus.dk Tue Feb 5 11:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 05 Feb 2008 18:02:16 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Tue Feb 5 17:11:40 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Wed, 06 Feb 2008 09:11:40 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A979CC.20571.A656998@stuart.lexacorp.com.pg> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From michael at ddisolutions.com.au Tue Feb 5 22:21:02 2008 From: michael at ddisolutions.com.au (Michael Maddison) Date: Wed, 6 Feb 2008 15:21:02 +1100 Subject: [dba-VB] Emailing: time_detail.rpt References: <59A61174B1F5B54B97FD4ADDE71E7D013BF274@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39353@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF275@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3936A@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF277@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39390@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF279@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E393C0@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF27B@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3944F@ssyd2800.rcl.domain> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D013BF27E@ddi-01.DDI.local> Hi Col and Denice, The final version of the time detail report is in place. I had to use the 'unscheduled' attribute to identify the OT. So any unscheduled OT will show in the ADJ/ENT column only. Let me know if there are any problems. FYI We are moving offices tomorrow and we cant be sure when Telstra will have the new phone lines ready or when our internet connection will be available. It is probably a good idea to catch me on the mobile till it gets sorted out. regards Michael Maddison DDI Solutions Pty Ltd michael at ddisolutions.com.au Bus: 0260400620 Mob: 0412620497 www.ddisolutions.com.au This Email message is for the sole use of the intended recipient and may contain confidential and privileged information. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply Email and destroy all copies as well as the original message. All views expressed in this Email are those of the sender, except where specifically stated otherwise, and do not necessarily reflect the views of DDi Solutions. From Gustav at cactus.dk Wed Feb 6 02:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 09:16:09 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart That is what I imagined initially. Problem is, however and to my surprise, that neither a DataSet nor a DataTable features an Update method. So what to do? I can't believe you have to revert to pure SQL commands to write back an update of a DataSet or DataTable?? /gustav >>> stuart at lexacorp.com.pg 06-02-2008 00:11 >>> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From Gustav at cactus.dk Wed Feb 6 07:30:02 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 14:30:02 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. In my code sample below, I marked rows as Modified with method SetModified. The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. For a row to be inserted by the later Update call, it has to have RowState set to Added. So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: // Mark row as modified. kundeRowS.SetModified(); or: // Mark row as new. kundeRowS.SetAdded(); When I changed the code from SetModified to SetAdded and replaced the Fill method with: kundeAdapterT.Update(kunderT); all records were written to the target table. Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: kunderT.Rows.Add(rowToAdd); RowState of those rows, I guess, will be switched to Added automatically. /gustav >>> Gustav at cactus.dk 05-02-2008 18:02 >>> Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Wed Feb 6 17:13:56 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Thu, 07 Feb 2008 09:13:56 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From cfoust at infostatsystems.com Wed Feb 6 19:25:32 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 6 Feb 2008 17:25:32 -0800 Subject: [dba-VB] Copy tables In-Reply-To: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> References: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Message-ID: I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 05:35:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 12:35:32 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_with_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From cfoust at infostatsystems.com Thu Feb 7 10:31:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 08:31:25 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_wit h_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a > button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 10:59:30 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 17:59:30 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 11:51:14 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 09:51:14 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: It clears the DataRow collection of the datatable. Charlotte -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 12:07:54 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 10:07:54 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 17:00:56 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 00:00:56 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 19:16:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 17:16:26 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 8 01:58:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 08:58:14 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks for that explanation, I can see why you do it this way. My situation is somewhat different as no data will be live - the source is an Access mdb permanently linked to the SQL Server - and the import will be run at regular intervals. Thus, should a row or two be lost during an import they will be fetched at the next run. As for the array compare, I will check out your idea of a temp table. /gustav >>> cfoust at infostatsystems.com 08-02-2008 02:16 >>> I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From Gustav at cactus.dk Fri Feb 8 10:41:39 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 17:41:39 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart et al The hash code of a row cannot be used as it is based on the parent (name of DateTable or DataSet object) and the position of the row in this, not the content. And ToString of the ItemArray and other objects just returns the name of the object, not the content or value of it. However, I located a very simple method to compare two arrays with "normal" content - not BLOBS or binaries - without having to code loops and so on. Once again, the .Net framework came to rescue - this time with Concat which (also) is able to concatenate the rows of an array. So: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableOrdreTableAdapter ordreSAdapter = new VrsSourceTableAdapters.DataTableOrdreTableAdapter(); VrsSource.DataTableOrdreDataTable ordreS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableOrdreTableAdapter ordreTAdapter = new VrsTargetTableAdapters.DataTableOrdreTableAdapter(); VrsTarget.DataTableOrdreDataTable ordreT; // DataTable for source. ordreS = ordreSAdapter.GetDataVrsOrdrer(); // DataTable for target. ordreT = ordreTAdapter.GetDataVrsOrdrer(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableOrdreRow foundRow = null; // Variables to hold hash codes of row contents. int hashSource; int hashTarget; foreach (VrsSource.DataTableOrdreRow ordreSRow in ordreS) { // Value of primary key to locate. key = ordreSRow.ordreNr; // Find a matching row in the target. foundRow = ordreT.FindByOrdreNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. ordreSRow.SetAdded(); // Append it to the target preserving the RowState. ordreT.ImportRow(ordreSRow); } else { // Row is found. Console.WriteLine(" Found: " + key.ToString()); // Calculate hash code to see if source row and target row match. hashSource = String.Concat(ordreSRow.ItemArray).GetHashCode(); hashTarget = String.Concat(foundRow.ItemArray).GetHashCode(); Console.WriteLine(" - Hash: " + hashSource.ToString() + " - " + hashTarget.ToString()); if (hashSource != hashTarget) { // The source row is updated. Console.WriteLine(" Modified OrdreNr: " + ordreSRow.ordreNr + ""); // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = ordreSRow.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } } // Write back to the database table the updated/appended rows of target DataTable. ordreTAdapter.Update(ordreT); Of course, if you have juxtaposed columns with similar content like: Val1 Val2 Concatenated string 3 44 344 34 4 344 just concatenating these may in some cases fail as the right column shows, but that is not the case for my current task. So now I only update modified records and append new records leaving the bunch of not modified records untouched! /gustav >>> Gustav at cactus.dk 08-02-2008 00:00 >>> Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From askolits at nni.com Fri Feb 8 15:35:40 2008 From: askolits at nni.com (John Skolits) Date: Fri, 8 Feb 2008 16:35:40 -0500 Subject: [dba-VB] VBA Excel Validation Message-ID: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits From shamil at users.mns.ru Sat Feb 9 04:26:38 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 13:26:38 +0300 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> Message-ID: <000f01c86b06$40ef9cc0$6401a8c0@nant> Hello John, Excel.Worksheet object has several events related to Excel.Range: Event Change(Target As Range) Event SelectionChange(Target As Range) Event BeforeDoubleClick(Target As Range, Cancel As Boolean) Event BeforeRightClick(Target As Range, Cancel As Boolean) You can try to explore and use these events... Excel.Workbook object has a couple of useful events to implement validation on whole worksheet/workbook level: Event BeforeSave(SaveAsUI As Boolean, Cancel As Boolean) Event BeforeClose(Cancel As Boolean) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 12:36 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] VBA Excel Validation This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From askolits at nni.com Sat Feb 9 09:25:35 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:25:35 -0500 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <001501c86b30$04e11040$0202fea9@LaptopXP> Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub From ssharkins at gmail.com Sat Feb 9 09:26:33 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Sat, 9 Feb 2008 10:26:33 -0500 Subject: [dba-VB] VBA Excel Validation References: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? From askolits at nni.com Sat Feb 9 09:33:34 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:33:34 -0500 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001501c86b30$04e11040$0202fea9@LaptopXP> Message-ID: <001601c86b31$229af7d0$0202fea9@LaptopXP> It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Sat Feb 9 10:20:27 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 19:20:27 +0300 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001601c86b31$229af7d0$0202fea9@LaptopXP> Message-ID: <000001c86b37$ae6f1d30$6401a8c0@nant> Congrats! :) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 6:34 PM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] RRESOVED! E: VBA Excel Validation It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Feb 10 04:18:26 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:18:26 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 04:25:18 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:25:18 +0100 Subject: [dba-VB] Installing SQL Server 2005 Management Studio after Visual Studio 2008 Message-ID: Hi all Found this tip which can save you a lot of time and lost hair: http://codingreflection.com/wordpress/?p=371 should you receive the message: "None of the selected features can be installed or upgraded." If so, use this command to run the install where d is your cd drive: d:\setup.exe SKUUPGRADE=1 /gustav From Gustav at cactus.dk Sun Feb 10 08:09:12 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 15:09:12 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi all Well, they (MS) are not kidding: http://blogs.msdn.com/somasegar/archive/2007/12/09/visual-studio-and-sql-server-2008.aspx For Visual Studio 2008 to support SQL Server 2008, we will be delivering a patch to coincide with the next CTP of SQL Server 2008. which raises the logical question: When is next CTP of SQL Server 2008 coming out? ... Monday, January 21, 2008 1:53 PM by Somasegar The next CTP of SQL Server 2008 will likely come out towards the end of Feburary - in time for the "VS2008, Windows Server 2008 and SQL Server 2008" launch. Good timing? /gustav >>> Gustav at cactus.dk 10-02-2008 11:18 >>> Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 11:14:00 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 18:14:00 +0100 Subject: [dba-VB] Visual Studio 2008: MSDTC on server 'servername' is unavailable (Solution) Message-ID: Hi all When you try to connect to a linked database on a remote server, you will probably succeed. However, when you try to preview the data (using the GetData.. method), you may receive this message just as data are to be retrieved: MSDTC on server 'servername' is unavailable I found the solution here: http://geekswithblogs.net/narent/archive/2006/10/09/93544.aspx Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Run MS DTC If you have the application and the SQL Server Data base in two different machines you must do that also Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Properties > MS DTC (TAB) > allow remote access In my case, the MS DTC service was running - I just had to touch it as described to get it working. Somewhat strange, I think, but who cares. Also, I modified the hosts and lmhosts.sam files to include the name lookup of the remote server as this is not a server with a public URL, but I'm not sure if that really is necessary as VS previously was perfectly able to preview a table of a normal database (but not of a linked) on that same server. hosts file: xxx.xxx.xxx.xxx servername # Description of server lmhosts.sam file: xxx.xxx.xxx.xxx servername #PRE #Description of server /gustav From accessd at shaw.ca Sun Feb 10 12:33:23 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sun, 10 Feb 2008 10:33:23 -0800 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP In-Reply-To: References: Message-ID: Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; Hi Jim True, but indeed I suspect this issue to be true also if the SQL Server 2008 is installed on a remote machine. VS2008 seems to have very few issues running on Vista Business which is what I use. /gustav >>> accessd at shaw.ca 10-02-2008 19:33 >>> Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; References: <000f01c86b06$40ef9cc0$6401a8c0@nant> <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Message-ID: <020e01c86c2f$1d233b10$0f01a8c0@officexp> Thanks for getting back to me. I ended up using one of the events to do a validation. But I may use your recommendation for something else. Thanks, John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Saturday, February 09, 2008 10:27 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VBA Excel Validation Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From accessd at shaw.ca Sat Feb 16 13:52:51 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sat, 16 Feb 2008 11:52:51 -0800 Subject: [dba-VB] New Library on the DBA site In-Reply-To: <003d01c870a3$a11e3230$4b3a8343@SusanOne> References: <001201c8709f$b7bb5e40$0300a8c0@danwaters> <003d01c870a3$a11e3230$4b3a8343@SusanOne> Message-ID: Hi All: There is a new Library section added to the DBA (http://www.databaseadvisors.com) web site. The section is split into 3 modules, one for books, one for articles and one for Podcast. This section is designed to high-lite the creations of list members. The present pages are by no means current or complete and are but a sample of what our members have created. If you have more links and contribution please email me, Jim Lawrence at webmaster at databaseadvisors.com Regards Jim From fhtapia at gmail.com Mon Feb 18 17:28:55 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 18 Feb 2008 15:28:55 -0800 Subject: [dba-VB] Building something quick 'n dirty Message-ID: I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From Gustav at cactus.dk Tue Feb 19 01:26:19 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 19 Feb 2008 08:26:19 +0100 Subject: [dba-VB] Building something quick 'n dirty Message-ID: Hi Francisco Given that time frame, CodeCharge comes to my mind: http://www.yessoftware.com/index2.php /gustav >>> fhtapia at gmail.com 19-02-2008 00:28 >>> I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From dwaters at usinternet.com Tue Feb 19 14:59:21 2008 From: dwaters at usinternet.com (Dan Waters) Date: Tue, 19 Feb 2008 14:59:21 -0600 Subject: [dba-VB] Any Students Out There? Message-ID: <004601c8733a$4ce7dba0$0300a8c0@danwaters> >From USA Today: Microsoft is giving students free access to its most sophisticated tools for writing software and making media-rich websites, a move that intensifies its competition with Adobe Systems and could challenge open source software's popularity. The Redmond-based software maker said late Monday it will let students download Visual Studio Professional Edition, a software development environment; Expression Studio, which includes graphic design and website and hybrid Web-desktop programming tools; and XNA Game Studio 2.0, a video game development program. From Gustav at cactus.dk Wed Feb 20 13:38:50 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 20 Feb 2008 20:38:50 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From Gustav at cactus.dk Thu Feb 21 06:33:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 21 Feb 2008 13:33:41 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From accessd at shaw.ca Thu Feb 21 14:52:57 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 21 Feb 2008 12:52:57 -0800 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? In-Reply-To: References: Message-ID: <0FF1B8B3E7B040B88549BFEE9E780C48@creativesystemdesigns.com> Hi Gustav: That is a helpful piece of information. Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 4:34 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 01:35:36 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 08:35:36 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From cfoust at infostatsystems.com Fri Feb 22 09:49:30 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 22 Feb 2008 07:49:30 -0800 Subject: [dba-VB] DataSet, view deleted rows In-Reply-To: References: Message-ID: You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 10:04:48 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 17:04:48 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi Charlotte That is of course more direct for single values. So much to learn ... /gustav >>> cfoust at infostatsystems.com 22-02-2008 16:49 >>> You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From Gustav at cactus.dk Wed Feb 27 08:18:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 15:18:41 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Johncliviger at aol.com Wed Feb 27 10:39:25 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 11:39:25 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: How about the app.config in the solution explorer johnc From Gustav at cactus.dk Wed Feb 27 11:15:58 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:15:58 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Well, that is what I thought. But it is read-only. Has to be edited manually via the GUI. /gustav >>> Johncliviger at aol.com 27-02-2008 17:39 >>> How about the app.config in the solution explorer johnc From Johncliviger at aol.com Wed Feb 27 11:50:59 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 12:50:59 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Wed Feb 27 11:54:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:54:47 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Yes, just use my normal address: gustav at cactus.dk /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Thu Feb 28 04:00:21 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 11:00:21 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Johncliviger at aol.com Thu Feb 28 04:50:46 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Thu, 28 Feb 2008 05:50:46 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Gustav mmmm...not sure I've got an answer....let me poke around in some other stuff I've got. johnc From BarbaraRyan at cox.net Thu Feb 28 06:13:09 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:13:09 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: Message-ID: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From BarbaraRyan at cox.net Thu Feb 28 06:49:25 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:49:25 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> Message-ID: <012701c87a08$593b88a0$0a00a8c0@PCRURI35> Sorry... I just realized that this is the VB mail list...Barb -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Barbara Ryan Sent: Thursday, February 28, 2008 7:13 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VS2005: Storing application settings I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Thu Feb 28 10:01:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 08:01:26 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Thu Feb 28 11:02:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 18:02:08 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From cfoust at infostatsystems.com Thu Feb 28 11:28:37 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 09:28:37 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 29 07:22:06 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:22:06 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte et al OK, I'm a child of VS2005, and when creating data sources the wizard kindly asks if you wish to save the connection strings in a file. Yes please, and that file happens to be app.config which you can read and write via the GUI. Now I realize that this file has entries for application settings as well as user settings where the main difference is that the application settings are read-only during runtime. This, of course, limits the value of using the application settings as you may have a need to store or edit application setting entries during runtime. I don't like to reinvent the wheel so I wondered if any method exists to circumvent this limitation other than to create a separate system as you have done. The only method I have seen is to open the app.config XML file directly as any other XML file: http://www.ryanfarley.com/blog/archive/2004/07/13/879.aspx To complicate matters, an advice is _not_ to do that because - as I mentioned previously - if the app.config file is read-only, it might be for a reason. That reason is explained here: http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav >>> cfoust at infostatsystems.com 28-02-2008 18:28 >>> OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Fri Feb 29 07:58:40 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:58:40 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From cfoust at infostatsystems.com Fri Feb 29 10:00:48 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 08:00:48 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From ssharkins at gmail.com Fri Feb 29 10:40:48 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 11:40:48 -0500 Subject: [dba-VB] VS2005: Storing application settings References: Message-ID: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, but > I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From cfoust at infostatsystems.com Fri Feb 29 11:29:51 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 09:29:51 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: Storing stuff in the registry is definitely discouraged in dotNet, Susan. And more and more, the registry is being locked down by system administrator. We started to run into problems with that in our extant Access applications. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Friday, February 29, 2008 8:41 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VS2005: Storing application settings > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, > but I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From Gustav at cactus.dk Fri Feb 29 11:31:04 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 18:31:04 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte Thanks. I'll stick to that method. /gustav >>> cfoust at infostatsystems.com 29-02-2008 17:00 >>> I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From ssharkins at gmail.com Fri Feb 29 11:47:20 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 12:47:20 -0500 Subject: [dba-VB] VS2005: Storing application settings References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: <013201c87afb$31a5d270$4b3a8343@SusanOne> Too bad... it's an easy solution. Susan H. > Storing stuff in the registry is definitely discouraged in dotNet, > Susan. And more and more, the registry is being locked down by system > administrator. We started to run into problems with that in our extant > Access applications. From Gustav at cactus.dk Fri Feb 1 12:49:54 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 01 Feb 2008 19:49:54 +0100 Subject: [dba-VB] Browsing records (was: Renaming DBA-VB) Message-ID: Hi all I just found out how ...: - click the top-right tiny arrow of the BindingNavigator. The BindingNavigator Tasks pane pops up - click the top item in this, "Embed in ToolStripContainer" A ToolStripContainer is created. Adjust the size of this or choose to dock it in the parent. Now the BindingNavigator can be moved around inside the ToolStripContainer. /gustav >>> Gustav at cactus.dk 25-10-2007 14:03:08 >>> Hi William Which control do you use for browsing records on forms? The default dataTableBindingNavigator? If so, have you managed to undock it so it can float? I have the GripStyle set to Visible, but the toolstrip is not to grip and move around. /gustav >>> wdhindman at dejpolsystems.com 25-10-2007 10:24 >>> Shamil ...yes, free!!! ...the express products value has been simply incredible for me ...I've yet to run into anything I could do with Access that I can't find a way to do with one or more of the express products ...and the amount/quality of code/support available on-line is every bit as good ...I still tend to model an app in Access first but I'm now starting to deliver in VS/SQL Server ...and the client sales are soooooo much easier in most cases. William ----- Original Message ----- From: "Shamil Salakhetdinov" To: Sent: Thursday, October 25, 2007 2:48 AM Subject: Re: [dba-VB] Renaming DBA-VB > <<< > I was unaware of the product cost.... >>>> > Hi Jim. > > Yes, I have just checked the price - it looks unaffordable for > small-/middle-size businesses. Yes, there is evaluation version but... > > I'd currently think that ASP.NET and C#/VB.NET(VS Express) + MS SQL 2005 > Express/Access backend DB is the best ever available toolset for Web (and > whatever else) real life business applications development... > > And they are free for download and use, aren't they?... > > > -- > Shamil > > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Thursday, October 25, 2007 5:46 AM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I do not usually answer my own emails but... > > I must qualify my last comments as I was unaware of the product cost which > had me fumbling for my oxygen mask as soon as I saw it. > > Fortunately there are evaluation copies available. > > Jim > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Wednesday, October 24, 2007 12:12 PM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I offer wonder why Ruby-on-rails is such a popular program considering > that > its performance is rated at one thirtieth of that of C and far below the > speed of any .Net flavour. > > A friend has recently been required to work with ROR and was not impressed > with performance and that it could be written so cryptic that he was > required to write extensive notes in the code. > > His recommendation for the finest .Net programming language is Eiffel: > http://archive.eiffel.com/doc/manuals/technology/dotnet/eiffelsharp/ > > Jim From pete.phillipps at ntlworld.com Sun Feb 3 15:00:26 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Sun, 3 Feb 2008 21:00:26 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com> <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> Message-ID: Hi Everyone, In VB6, the following code sets/unsets the text box to bold and/italic depending on the value of the checkboxes: txtMyText.Font.Bold = chkBold.Value txtMyText.Font.Italic = chkItalic.Value How do you do the same in VB2005? Pete From stuart at lexacorp.com.pg Sun Feb 3 17:42:31 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Mon, 04 Feb 2008 09:42:31 +1000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, Message-ID: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> On 3 Feb 2008 at 21:00, Pete Phillipps wrote: > In VB6, the following code sets/unsets the text box to bold > and/italic depending on the value of the checkboxes: > txtMyText.Font.Bold = chkBold.Value > txtMyText.Font.Italic = chkItalic.Value > > How do you do the same in VB2005? > Private Sub chkBoxes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged, chkItalic.CheckedChanged Dim intFontAttribs As Integer intFontAttribs = IIf(chkBold.Checked, FontStyle.Bold, 0) + IIf(chkItalic.Checked, FontStyle.Italic, 0) txtmyText.Font = New Font(txtmyText.Font, intFontAttribs) End Sub From Gustav at cactus.dk Mon Feb 4 11:41:29 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Mon, 04 Feb 2008 18:41:29 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi all I have created two tableadapters, a source and a target, and need to browse through the source looking for rows and, when a row meeting some conditions is found, copy this to the target. What is the best method? /gustav From pete.phillipps at ntlworld.com Mon Feb 4 12:40:52 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Mon, 4 Feb 2008 18:40:52 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> Message-ID: Hi Stuart, <> Thanks, it's so simple when you know what you're doing :-) Pete "Many [wargame] battles have been fought and won by soldiers nourished on beer" - Frederick the Great, 1777 Download VIEW FROM THE TRENCHES (Britain's Premier ASL Journal) free from http://www.vftt.co.uk Get the latest news about HEROES(ASL in Blackpool) at http://www.vftt.co.uk/heroesdetails.asp Get the latest news about INTENSIVE FIRE (Britain's biggest ASL tournament) at http://www.vftt.co.uk/ifdetails.asp Get the latest UK ASL Tournament news at http://www.asltourneys.co.uk Support the best at http://www.manutd.com/ From stuart at lexacorp.com.pg Mon Feb 4 17:06:55 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Tue, 05 Feb 2008 09:06:55 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A8272F.14339.53AB50B@stuart.lexacorp.com.pg> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From Gustav at cactus.dk Tue Feb 5 11:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 05 Feb 2008 18:02:16 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Tue Feb 5 17:11:40 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Wed, 06 Feb 2008 09:11:40 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A979CC.20571.A656998@stuart.lexacorp.com.pg> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From michael at ddisolutions.com.au Tue Feb 5 22:21:02 2008 From: michael at ddisolutions.com.au (Michael Maddison) Date: Wed, 6 Feb 2008 15:21:02 +1100 Subject: [dba-VB] Emailing: time_detail.rpt References: <59A61174B1F5B54B97FD4ADDE71E7D013BF274@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39353@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF275@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3936A@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF277@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39390@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF279@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E393C0@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF27B@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3944F@ssyd2800.rcl.domain> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D013BF27E@ddi-01.DDI.local> Hi Col and Denice, The final version of the time detail report is in place. I had to use the 'unscheduled' attribute to identify the OT. So any unscheduled OT will show in the ADJ/ENT column only. Let me know if there are any problems. FYI We are moving offices tomorrow and we cant be sure when Telstra will have the new phone lines ready or when our internet connection will be available. It is probably a good idea to catch me on the mobile till it gets sorted out. regards Michael Maddison DDI Solutions Pty Ltd michael at ddisolutions.com.au Bus: 0260400620 Mob: 0412620497 www.ddisolutions.com.au This Email message is for the sole use of the intended recipient and may contain confidential and privileged information. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply Email and destroy all copies as well as the original message. All views expressed in this Email are those of the sender, except where specifically stated otherwise, and do not necessarily reflect the views of DDi Solutions. From Gustav at cactus.dk Wed Feb 6 02:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 09:16:09 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart That is what I imagined initially. Problem is, however and to my surprise, that neither a DataSet nor a DataTable features an Update method. So what to do? I can't believe you have to revert to pure SQL commands to write back an update of a DataSet or DataTable?? /gustav >>> stuart at lexacorp.com.pg 06-02-2008 00:11 >>> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From Gustav at cactus.dk Wed Feb 6 07:30:02 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 14:30:02 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. In my code sample below, I marked rows as Modified with method SetModified. The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. For a row to be inserted by the later Update call, it has to have RowState set to Added. So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: // Mark row as modified. kundeRowS.SetModified(); or: // Mark row as new. kundeRowS.SetAdded(); When I changed the code from SetModified to SetAdded and replaced the Fill method with: kundeAdapterT.Update(kunderT); all records were written to the target table. Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: kunderT.Rows.Add(rowToAdd); RowState of those rows, I guess, will be switched to Added automatically. /gustav >>> Gustav at cactus.dk 05-02-2008 18:02 >>> Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Wed Feb 6 17:13:56 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Thu, 07 Feb 2008 09:13:56 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From cfoust at infostatsystems.com Wed Feb 6 19:25:32 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 6 Feb 2008 17:25:32 -0800 Subject: [dba-VB] Copy tables In-Reply-To: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> References: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Message-ID: I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 05:35:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 12:35:32 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_with_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From cfoust at infostatsystems.com Thu Feb 7 10:31:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 08:31:25 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_wit h_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a > button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 10:59:30 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 17:59:30 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 11:51:14 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 09:51:14 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: It clears the DataRow collection of the datatable. Charlotte -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 12:07:54 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 10:07:54 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 17:00:56 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 00:00:56 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 19:16:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 17:16:26 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 8 01:58:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 08:58:14 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks for that explanation, I can see why you do it this way. My situation is somewhat different as no data will be live - the source is an Access mdb permanently linked to the SQL Server - and the import will be run at regular intervals. Thus, should a row or two be lost during an import they will be fetched at the next run. As for the array compare, I will check out your idea of a temp table. /gustav >>> cfoust at infostatsystems.com 08-02-2008 02:16 >>> I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From Gustav at cactus.dk Fri Feb 8 10:41:39 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 17:41:39 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart et al The hash code of a row cannot be used as it is based on the parent (name of DateTable or DataSet object) and the position of the row in this, not the content. And ToString of the ItemArray and other objects just returns the name of the object, not the content or value of it. However, I located a very simple method to compare two arrays with "normal" content - not BLOBS or binaries - without having to code loops and so on. Once again, the .Net framework came to rescue - this time with Concat which (also) is able to concatenate the rows of an array. So: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableOrdreTableAdapter ordreSAdapter = new VrsSourceTableAdapters.DataTableOrdreTableAdapter(); VrsSource.DataTableOrdreDataTable ordreS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableOrdreTableAdapter ordreTAdapter = new VrsTargetTableAdapters.DataTableOrdreTableAdapter(); VrsTarget.DataTableOrdreDataTable ordreT; // DataTable for source. ordreS = ordreSAdapter.GetDataVrsOrdrer(); // DataTable for target. ordreT = ordreTAdapter.GetDataVrsOrdrer(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableOrdreRow foundRow = null; // Variables to hold hash codes of row contents. int hashSource; int hashTarget; foreach (VrsSource.DataTableOrdreRow ordreSRow in ordreS) { // Value of primary key to locate. key = ordreSRow.ordreNr; // Find a matching row in the target. foundRow = ordreT.FindByOrdreNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. ordreSRow.SetAdded(); // Append it to the target preserving the RowState. ordreT.ImportRow(ordreSRow); } else { // Row is found. Console.WriteLine(" Found: " + key.ToString()); // Calculate hash code to see if source row and target row match. hashSource = String.Concat(ordreSRow.ItemArray).GetHashCode(); hashTarget = String.Concat(foundRow.ItemArray).GetHashCode(); Console.WriteLine(" - Hash: " + hashSource.ToString() + " - " + hashTarget.ToString()); if (hashSource != hashTarget) { // The source row is updated. Console.WriteLine(" Modified OrdreNr: " + ordreSRow.ordreNr + ""); // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = ordreSRow.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } } // Write back to the database table the updated/appended rows of target DataTable. ordreTAdapter.Update(ordreT); Of course, if you have juxtaposed columns with similar content like: Val1 Val2 Concatenated string 3 44 344 34 4 344 just concatenating these may in some cases fail as the right column shows, but that is not the case for my current task. So now I only update modified records and append new records leaving the bunch of not modified records untouched! /gustav >>> Gustav at cactus.dk 08-02-2008 00:00 >>> Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From askolits at nni.com Fri Feb 8 15:35:40 2008 From: askolits at nni.com (John Skolits) Date: Fri, 8 Feb 2008 16:35:40 -0500 Subject: [dba-VB] VBA Excel Validation Message-ID: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits From shamil at users.mns.ru Sat Feb 9 04:26:38 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 13:26:38 +0300 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> Message-ID: <000f01c86b06$40ef9cc0$6401a8c0@nant> Hello John, Excel.Worksheet object has several events related to Excel.Range: Event Change(Target As Range) Event SelectionChange(Target As Range) Event BeforeDoubleClick(Target As Range, Cancel As Boolean) Event BeforeRightClick(Target As Range, Cancel As Boolean) You can try to explore and use these events... Excel.Workbook object has a couple of useful events to implement validation on whole worksheet/workbook level: Event BeforeSave(SaveAsUI As Boolean, Cancel As Boolean) Event BeforeClose(Cancel As Boolean) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 12:36 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] VBA Excel Validation This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From askolits at nni.com Sat Feb 9 09:25:35 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:25:35 -0500 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <001501c86b30$04e11040$0202fea9@LaptopXP> Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub From ssharkins at gmail.com Sat Feb 9 09:26:33 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Sat, 9 Feb 2008 10:26:33 -0500 Subject: [dba-VB] VBA Excel Validation References: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? From askolits at nni.com Sat Feb 9 09:33:34 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:33:34 -0500 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001501c86b30$04e11040$0202fea9@LaptopXP> Message-ID: <001601c86b31$229af7d0$0202fea9@LaptopXP> It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Sat Feb 9 10:20:27 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 19:20:27 +0300 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001601c86b31$229af7d0$0202fea9@LaptopXP> Message-ID: <000001c86b37$ae6f1d30$6401a8c0@nant> Congrats! :) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 6:34 PM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] RRESOVED! E: VBA Excel Validation It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Feb 10 04:18:26 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:18:26 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 04:25:18 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:25:18 +0100 Subject: [dba-VB] Installing SQL Server 2005 Management Studio after Visual Studio 2008 Message-ID: Hi all Found this tip which can save you a lot of time and lost hair: http://codingreflection.com/wordpress/?p=371 should you receive the message: "None of the selected features can be installed or upgraded." If so, use this command to run the install where d is your cd drive: d:\setup.exe SKUUPGRADE=1 /gustav From Gustav at cactus.dk Sun Feb 10 08:09:12 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 15:09:12 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi all Well, they (MS) are not kidding: http://blogs.msdn.com/somasegar/archive/2007/12/09/visual-studio-and-sql-server-2008.aspx For Visual Studio 2008 to support SQL Server 2008, we will be delivering a patch to coincide with the next CTP of SQL Server 2008. which raises the logical question: When is next CTP of SQL Server 2008 coming out? ... Monday, January 21, 2008 1:53 PM by Somasegar The next CTP of SQL Server 2008 will likely come out towards the end of Feburary - in time for the "VS2008, Windows Server 2008 and SQL Server 2008" launch. Good timing? /gustav >>> Gustav at cactus.dk 10-02-2008 11:18 >>> Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 11:14:00 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 18:14:00 +0100 Subject: [dba-VB] Visual Studio 2008: MSDTC on server 'servername' is unavailable (Solution) Message-ID: Hi all When you try to connect to a linked database on a remote server, you will probably succeed. However, when you try to preview the data (using the GetData.. method), you may receive this message just as data are to be retrieved: MSDTC on server 'servername' is unavailable I found the solution here: http://geekswithblogs.net/narent/archive/2006/10/09/93544.aspx Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Run MS DTC If you have the application and the SQL Server Data base in two different machines you must do that also Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Properties > MS DTC (TAB) > allow remote access In my case, the MS DTC service was running - I just had to touch it as described to get it working. Somewhat strange, I think, but who cares. Also, I modified the hosts and lmhosts.sam files to include the name lookup of the remote server as this is not a server with a public URL, but I'm not sure if that really is necessary as VS previously was perfectly able to preview a table of a normal database (but not of a linked) on that same server. hosts file: xxx.xxx.xxx.xxx servername # Description of server lmhosts.sam file: xxx.xxx.xxx.xxx servername #PRE #Description of server /gustav From accessd at shaw.ca Sun Feb 10 12:33:23 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sun, 10 Feb 2008 10:33:23 -0800 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP In-Reply-To: References: Message-ID: Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; Hi Jim True, but indeed I suspect this issue to be true also if the SQL Server 2008 is installed on a remote machine. VS2008 seems to have very few issues running on Vista Business which is what I use. /gustav >>> accessd at shaw.ca 10-02-2008 19:33 >>> Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; References: <000f01c86b06$40ef9cc0$6401a8c0@nant> <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Message-ID: <020e01c86c2f$1d233b10$0f01a8c0@officexp> Thanks for getting back to me. I ended up using one of the events to do a validation. But I may use your recommendation for something else. Thanks, John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Saturday, February 09, 2008 10:27 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VBA Excel Validation Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From accessd at shaw.ca Sat Feb 16 13:52:51 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sat, 16 Feb 2008 11:52:51 -0800 Subject: [dba-VB] New Library on the DBA site In-Reply-To: <003d01c870a3$a11e3230$4b3a8343@SusanOne> References: <001201c8709f$b7bb5e40$0300a8c0@danwaters> <003d01c870a3$a11e3230$4b3a8343@SusanOne> Message-ID: Hi All: There is a new Library section added to the DBA (http://www.databaseadvisors.com) web site. The section is split into 3 modules, one for books, one for articles and one for Podcast. This section is designed to high-lite the creations of list members. The present pages are by no means current or complete and are but a sample of what our members have created. If you have more links and contribution please email me, Jim Lawrence at webmaster at databaseadvisors.com Regards Jim From fhtapia at gmail.com Mon Feb 18 17:28:55 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 18 Feb 2008 15:28:55 -0800 Subject: [dba-VB] Building something quick 'n dirty Message-ID: I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From Gustav at cactus.dk Tue Feb 19 01:26:19 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 19 Feb 2008 08:26:19 +0100 Subject: [dba-VB] Building something quick 'n dirty Message-ID: Hi Francisco Given that time frame, CodeCharge comes to my mind: http://www.yessoftware.com/index2.php /gustav >>> fhtapia at gmail.com 19-02-2008 00:28 >>> I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From dwaters at usinternet.com Tue Feb 19 14:59:21 2008 From: dwaters at usinternet.com (Dan Waters) Date: Tue, 19 Feb 2008 14:59:21 -0600 Subject: [dba-VB] Any Students Out There? Message-ID: <004601c8733a$4ce7dba0$0300a8c0@danwaters> >From USA Today: Microsoft is giving students free access to its most sophisticated tools for writing software and making media-rich websites, a move that intensifies its competition with Adobe Systems and could challenge open source software's popularity. The Redmond-based software maker said late Monday it will let students download Visual Studio Professional Edition, a software development environment; Expression Studio, which includes graphic design and website and hybrid Web-desktop programming tools; and XNA Game Studio 2.0, a video game development program. From Gustav at cactus.dk Wed Feb 20 13:38:50 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 20 Feb 2008 20:38:50 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From Gustav at cactus.dk Thu Feb 21 06:33:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 21 Feb 2008 13:33:41 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From accessd at shaw.ca Thu Feb 21 14:52:57 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 21 Feb 2008 12:52:57 -0800 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? In-Reply-To: References: Message-ID: <0FF1B8B3E7B040B88549BFEE9E780C48@creativesystemdesigns.com> Hi Gustav: That is a helpful piece of information. Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 4:34 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 01:35:36 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 08:35:36 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From cfoust at infostatsystems.com Fri Feb 22 09:49:30 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 22 Feb 2008 07:49:30 -0800 Subject: [dba-VB] DataSet, view deleted rows In-Reply-To: References: Message-ID: You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 10:04:48 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 17:04:48 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi Charlotte That is of course more direct for single values. So much to learn ... /gustav >>> cfoust at infostatsystems.com 22-02-2008 16:49 >>> You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From Gustav at cactus.dk Wed Feb 27 08:18:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 15:18:41 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Johncliviger at aol.com Wed Feb 27 10:39:25 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 11:39:25 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: How about the app.config in the solution explorer johnc From Gustav at cactus.dk Wed Feb 27 11:15:58 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:15:58 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Well, that is what I thought. But it is read-only. Has to be edited manually via the GUI. /gustav >>> Johncliviger at aol.com 27-02-2008 17:39 >>> How about the app.config in the solution explorer johnc From Johncliviger at aol.com Wed Feb 27 11:50:59 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 12:50:59 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Wed Feb 27 11:54:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:54:47 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Yes, just use my normal address: gustav at cactus.dk /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Thu Feb 28 04:00:21 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 11:00:21 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Johncliviger at aol.com Thu Feb 28 04:50:46 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Thu, 28 Feb 2008 05:50:46 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Gustav mmmm...not sure I've got an answer....let me poke around in some other stuff I've got. johnc From BarbaraRyan at cox.net Thu Feb 28 06:13:09 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:13:09 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: Message-ID: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From BarbaraRyan at cox.net Thu Feb 28 06:49:25 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:49:25 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> Message-ID: <012701c87a08$593b88a0$0a00a8c0@PCRURI35> Sorry... I just realized that this is the VB mail list...Barb -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Barbara Ryan Sent: Thursday, February 28, 2008 7:13 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VS2005: Storing application settings I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Thu Feb 28 10:01:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 08:01:26 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Thu Feb 28 11:02:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 18:02:08 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From cfoust at infostatsystems.com Thu Feb 28 11:28:37 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 09:28:37 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 29 07:22:06 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:22:06 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte et al OK, I'm a child of VS2005, and when creating data sources the wizard kindly asks if you wish to save the connection strings in a file. Yes please, and that file happens to be app.config which you can read and write via the GUI. Now I realize that this file has entries for application settings as well as user settings where the main difference is that the application settings are read-only during runtime. This, of course, limits the value of using the application settings as you may have a need to store or edit application setting entries during runtime. I don't like to reinvent the wheel so I wondered if any method exists to circumvent this limitation other than to create a separate system as you have done. The only method I have seen is to open the app.config XML file directly as any other XML file: http://www.ryanfarley.com/blog/archive/2004/07/13/879.aspx To complicate matters, an advice is _not_ to do that because - as I mentioned previously - if the app.config file is read-only, it might be for a reason. That reason is explained here: http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav >>> cfoust at infostatsystems.com 28-02-2008 18:28 >>> OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Fri Feb 29 07:58:40 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:58:40 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From cfoust at infostatsystems.com Fri Feb 29 10:00:48 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 08:00:48 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From ssharkins at gmail.com Fri Feb 29 10:40:48 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 11:40:48 -0500 Subject: [dba-VB] VS2005: Storing application settings References: Message-ID: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, but > I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From cfoust at infostatsystems.com Fri Feb 29 11:29:51 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 09:29:51 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: Storing stuff in the registry is definitely discouraged in dotNet, Susan. And more and more, the registry is being locked down by system administrator. We started to run into problems with that in our extant Access applications. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Friday, February 29, 2008 8:41 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VS2005: Storing application settings > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, > but I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From Gustav at cactus.dk Fri Feb 29 11:31:04 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 18:31:04 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte Thanks. I'll stick to that method. /gustav >>> cfoust at infostatsystems.com 29-02-2008 17:00 >>> I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From ssharkins at gmail.com Fri Feb 29 11:47:20 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 12:47:20 -0500 Subject: [dba-VB] VS2005: Storing application settings References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: <013201c87afb$31a5d270$4b3a8343@SusanOne> Too bad... it's an easy solution. Susan H. > Storing stuff in the registry is definitely discouraged in dotNet, > Susan. And more and more, the registry is being locked down by system > administrator. We started to run into problems with that in our extant > Access applications. From Gustav at cactus.dk Fri Feb 1 12:49:54 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 01 Feb 2008 19:49:54 +0100 Subject: [dba-VB] Browsing records (was: Renaming DBA-VB) Message-ID: Hi all I just found out how ...: - click the top-right tiny arrow of the BindingNavigator. The BindingNavigator Tasks pane pops up - click the top item in this, "Embed in ToolStripContainer" A ToolStripContainer is created. Adjust the size of this or choose to dock it in the parent. Now the BindingNavigator can be moved around inside the ToolStripContainer. /gustav >>> Gustav at cactus.dk 25-10-2007 14:03:08 >>> Hi William Which control do you use for browsing records on forms? The default dataTableBindingNavigator? If so, have you managed to undock it so it can float? I have the GripStyle set to Visible, but the toolstrip is not to grip and move around. /gustav >>> wdhindman at dejpolsystems.com 25-10-2007 10:24 >>> Shamil ...yes, free!!! ...the express products value has been simply incredible for me ...I've yet to run into anything I could do with Access that I can't find a way to do with one or more of the express products ...and the amount/quality of code/support available on-line is every bit as good ...I still tend to model an app in Access first but I'm now starting to deliver in VS/SQL Server ...and the client sales are soooooo much easier in most cases. William ----- Original Message ----- From: "Shamil Salakhetdinov" To: Sent: Thursday, October 25, 2007 2:48 AM Subject: Re: [dba-VB] Renaming DBA-VB > <<< > I was unaware of the product cost.... >>>> > Hi Jim. > > Yes, I have just checked the price - it looks unaffordable for > small-/middle-size businesses. Yes, there is evaluation version but... > > I'd currently think that ASP.NET and C#/VB.NET(VS Express) + MS SQL 2005 > Express/Access backend DB is the best ever available toolset for Web (and > whatever else) real life business applications development... > > And they are free for download and use, aren't they?... > > > -- > Shamil > > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Thursday, October 25, 2007 5:46 AM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I do not usually answer my own emails but... > > I must qualify my last comments as I was unaware of the product cost which > had me fumbling for my oxygen mask as soon as I saw it. > > Fortunately there are evaluation copies available. > > Jim > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence > Sent: Wednesday, October 24, 2007 12:12 PM > To: dba-vb at databaseadvisors.com > Subject: Re: [dba-VB] Renaming DBA-VB > > I offer wonder why Ruby-on-rails is such a popular program considering > that > its performance is rated at one thirtieth of that of C and far below the > speed of any .Net flavour. > > A friend has recently been required to work with ROR and was not impressed > with performance and that it could be written so cryptic that he was > required to write extensive notes in the code. > > His recommendation for the finest .Net programming language is Eiffel: > http://archive.eiffel.com/doc/manuals/technology/dotnet/eiffelsharp/ > > Jim From pete.phillipps at ntlworld.com Sun Feb 3 15:00:26 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Sun, 3 Feb 2008 21:00:26 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com> <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit> Message-ID: Hi Everyone, In VB6, the following code sets/unsets the text box to bold and/italic depending on the value of the checkboxes: txtMyText.Font.Bold = chkBold.Value txtMyText.Font.Italic = chkItalic.Value How do you do the same in VB2005? Pete From stuart at lexacorp.com.pg Sun Feb 3 17:42:31 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Mon, 04 Feb 2008 09:42:31 +1000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, Message-ID: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> On 3 Feb 2008 at 21:00, Pete Phillipps wrote: > In VB6, the following code sets/unsets the text box to bold > and/italic depending on the value of the checkboxes: > txtMyText.Font.Bold = chkBold.Value > txtMyText.Font.Italic = chkItalic.Value > > How do you do the same in VB2005? > Private Sub chkBoxes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged, chkItalic.CheckedChanged Dim intFontAttribs As Integer intFontAttribs = IIf(chkBold.Checked, FontStyle.Bold, 0) + IIf(chkItalic.Checked, FontStyle.Italic, 0) txtmyText.Font = New Font(txtmyText.Font, intFontAttribs) End Sub From Gustav at cactus.dk Mon Feb 4 11:41:29 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Mon, 04 Feb 2008 18:41:29 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi all I have created two tableadapters, a source and a target, and need to browse through the source looking for rows and, when a row meeting some conditions is found, copy this to the target. What is the best method? /gustav From pete.phillipps at ntlworld.com Mon Feb 4 12:40:52 2008 From: pete.phillipps at ntlworld.com (Pete Phillipps) Date: Mon, 4 Feb 2008 18:40:52 -0000 Subject: [dba-VB] VB2005 Programmatically set text box font values In-Reply-To: <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> References: <20070711032439.67F66BE14@smtp-auth.no-ip.com>, <000901c7c3aa$18f4c6e0$2f01a8c0@Kermit>, <47A6DE07.15101.34F03F@stuart.lexacorp.com.pg> Message-ID: Hi Stuart, <> Thanks, it's so simple when you know what you're doing :-) Pete "Many [wargame] battles have been fought and won by soldiers nourished on beer" - Frederick the Great, 1777 Download VIEW FROM THE TRENCHES (Britain's Premier ASL Journal) free from http://www.vftt.co.uk Get the latest news about HEROES(ASL in Blackpool) at http://www.vftt.co.uk/heroesdetails.asp Get the latest news about INTENSIVE FIRE (Britain's biggest ASL tournament) at http://www.vftt.co.uk/ifdetails.asp Get the latest UK ASL Tournament news at http://www.asltourneys.co.uk Support the best at http://www.manutd.com/ From stuart at lexacorp.com.pg Mon Feb 4 17:06:55 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Tue, 05 Feb 2008 09:06:55 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A8272F.14339.53AB50B@stuart.lexacorp.com.pg> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From Gustav at cactus.dk Tue Feb 5 11:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 05 Feb 2008 18:02:16 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Tue Feb 5 17:11:40 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Wed, 06 Feb 2008 09:11:40 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47A979CC.20571.A656998@stuart.lexacorp.com.pg> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From michael at ddisolutions.com.au Tue Feb 5 22:21:02 2008 From: michael at ddisolutions.com.au (Michael Maddison) Date: Wed, 6 Feb 2008 15:21:02 +1100 Subject: [dba-VB] Emailing: time_detail.rpt References: <59A61174B1F5B54B97FD4ADDE71E7D013BF274@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39353@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF275@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3936A@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF277@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E39390@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF279@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E393C0@ssyd2800.rcl.domain> <59A61174B1F5B54B97FD4ADDE71E7D013BF27B@ddi-01.DDI.local> <81D50B42E16EBE40A52445A4C7DD9B67E3944F@ssyd2800.rcl.domain> Message-ID: <59A61174B1F5B54B97FD4ADDE71E7D013BF27E@ddi-01.DDI.local> Hi Col and Denice, The final version of the time detail report is in place. I had to use the 'unscheduled' attribute to identify the OT. So any unscheduled OT will show in the ADJ/ENT column only. Let me know if there are any problems. FYI We are moving offices tomorrow and we cant be sure when Telstra will have the new phone lines ready or when our internet connection will be available. It is probably a good idea to catch me on the mobile till it gets sorted out. regards Michael Maddison DDI Solutions Pty Ltd michael at ddisolutions.com.au Bus: 0260400620 Mob: 0412620497 www.ddisolutions.com.au This Email message is for the sole use of the intended recipient and may contain confidential and privileged information. Any unauthorised review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply Email and destroy all copies as well as the original message. All views expressed in this Email are those of the sender, except where specifically stated otherwise, and do not necessarily reflect the views of DDi Solutions. From Gustav at cactus.dk Wed Feb 6 02:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 09:16:09 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart That is what I imagined initially. Problem is, however and to my surprise, that neither a DataSet nor a DataTable features an Update method. So what to do? I can't believe you have to revert to pure SQL commands to write back an update of a DataSet or DataTable?? /gustav >>> stuart at lexacorp.com.pg 06-02-2008 00:11 >>> I think you need to follow with kunderT.Update to update the underlying database from the TableAdapter. On 5 Feb 2008 at 18:02, Gustav Brock wrote: > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From Gustav at cactus.dk Wed Feb 6 07:30:02 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 06 Feb 2008 14:30:02 +0100 Subject: [dba-VB] Copy tables Message-ID: Hi Stuart et al Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. In my code sample below, I marked rows as Modified with method SetModified. The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. For a row to be inserted by the later Update call, it has to have RowState set to Added. So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: // Mark row as modified. kundeRowS.SetModified(); or: // Mark row as new. kundeRowS.SetAdded(); When I changed the code from SetModified to SetAdded and replaced the Fill method with: kundeAdapterT.Update(kunderT); all records were written to the target table. Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: kunderT.Rows.Add(rowToAdd); RowState of those rows, I guess, will be switched to Added automatically. /gustav >>> Gustav at cactus.dk 05-02-2008 18:02 >>> Hi Stuart et al No there is no GUI, just code. I have some code like this. It add rows but will not save them to the database table: VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; kunderS = kundeAdapterS.GetDataVrsKunder(); kunderT = kundeAdapterT.GetDataVrsKunder(); foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { Console.WriteLine("Kunde: " + kundeRowS.navn + ""); Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); // Mark row as modified. kundeRowS.SetModified(); kunderT.ImportRow(kundeRowS); } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); kundeAdapterT.FillVrsKunder(kunderT); Target table is residing in MSDE. Count of s returns the count of records to add. Count of t returns existing records + count of records to add. What am I missing? /gustav >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> Do you mean have the user physically browse through the rows looking for specific records? If that is the case, I would probably go with a DatagridView bound to the source data. When the user selects a row (double click, highlight and click a button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. On 4 Feb 2008 at 18:41, Gustav Brock wrote: > Hi all > > I have created two tableadapters, a source and a target, and need to > browse through the source looking for rows and, when a row meeting > some conditions is found, copy this to the target. What is the best > method? > > /gustav From stuart at lexacorp.com.pg Wed Feb 6 17:13:56 2008 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Thu, 07 Feb 2008 09:13:56 +1000 Subject: [dba-VB] Copy tables In-Reply-To: References: Message-ID: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > From cfoust at infostatsystems.com Wed Feb 6 19:25:32 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 6 Feb 2008 17:25:32 -0800 Subject: [dba-VB] Copy tables In-Reply-To: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> References: <47AACBD4.10871.F8DD6B5@stuart.lexacorp.com.pg> Message-ID: I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com > _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 05:35:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 12:35:32 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_with_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a button or whatever), read the > row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav From cfoust at infostatsystems.com Thu Feb 7 10:31:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 08:31:25 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte and Stuart That's a good idea - if the code works. I have not much hair left after having browsed thousands of sites (so it feels). I thought it would be a simple job to locate code somewhere around that I could modify, but no. Well, yes, but that is basic code snippets working with connection strings and SQL commands and so on for ASP kiddies. This must be very special, though I thought it to be some kind of standard routine. But no. So again, should you ever have a task like the subject to do, make a note of this method. Main issue is that the DataTableAdapter wizard creates a buggy SQL Update command which raised the error when you finally call the Update method of the DataTableAdapter: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." The key to solve this I found here: http://geekswithblogs.net/gaijin42/archive/2007/09/05/update_dataset_wit h_new_rows_acceptchanges_setmodified_orm_business_objects.aspx During testing I received first the "Concurrency violation" message and only a Select statement was found for the Update SQL command. Later - somehow - the wizard generated the full Update SQL command with a bunch of parameters - and that failed too. Then I edited the Update SQL as described by Jason to include the parameter for the primary key only. That worked! Finally, I found that the simplest method to copy a row of one type to a row of another type (remember, source and target are from different DataTableAdapters) is to copy the ItemArray. So now I can update and append to the target rows from the source rows in one go with this code: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = new VrsSourceTableAdapters.DataTableKundeTableAdapter(); VrsSource.DataTableKundeDataTable kunderS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = new VrsTargetTableAdapters.DataTableKundeTableAdapter(); VrsTarget.DataTableKundeDataTable kunderT; // DataTable for source. kunderS = kundeAdapterS.GetDataVrsKunder(); // DataTable for target. kunderT = kundeAdapterT.GetDataVrsKunder(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableKundeRow foundRow = null; foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) { // Value of primary key to locate. key = kundeRowS.kundeNr; // Find a matching row in the target. foundRow = kunderT.FindByKundeNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. kundeRowS.SetAdded(); // Append it to the target preserving the RowState. kunderT.ImportRow(kundeRowS); } else { // Row is found. // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = kundeRowS.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } Console.WriteLine("s: " + kunderS.Count.ToString()); Console.WriteLine("t: " + kunderT.Count.ToString()); // Write back to the database table the updated target DataTable. kundeAdapterT.Update(kunderT); // Call AcceptChanges if needed for further processing. // kunderT.AcceptChanges(); Still, if anyone have a better method, I'm all ears. This is by no means an expert area for me. /gustav >>> cfoust at infostatsystems.com 07-02-2008 02:25 >>> I've fallen over that one before too, and the best way to avoid that is to put the code in a public helper class and then call it when you need to do that task. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Wednesday, February 06, 2008 3:14 PM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] Copy tables Glad it's not just me trying to get my head around .Net and data at the moment. :-) After 15 years of Access and classic VB development, there's so much new stuff to learn here :-( On 6 Feb 2008 at 14:30, Gustav Brock wrote: > Hi Stuart et al > > Oh my, make a note on this should you ever wish to copy data between DataSets or DataTables with method ImportRow. > > The secret is the value of property RowState of the individual rows. Rows read from a table have a RowState of Unchanged. > If a row is copied to another DataSet/DataTable by method ImportRow, RowState remains Unchanged. > > In my code sample below, I marked rows as Modified with method SetModified. > > The Update method of the DataTableAdapter, which is called to write the data rows to the underlying table, is quite clever as it doesn't touch rows with RowState Unchanged. > However, rows with RowState Modified will only be used to update existing records in the target table, thus it will not attempt to append or insert any such row. > > For a row to be inserted by the later Update call, it has to have RowState set to Added. > > So, for my code below, I have to decide if a row should update an existing record, or if it should be appended, or if it should be ignored - and then call the method SetModified or SetAdded or nothing: > > // Mark row as modified. > kundeRowS.SetModified(); > or: > // Mark row as new. > kundeRowS.SetAdded(); > > When I changed the code from SetModified to SetAdded and replaced the Fill method with: > > kundeAdapterT.Update(kunderT); > > all records were written to the target table. > > Of course, if you can write your code to add rows not using method ImportRow - with LoadDataRow or like: > > kunderT.Rows.Add(rowToAdd); > > RowState of those rows, I guess, will be switched to Added automatically. > > /gustav > > > >>> Gustav at cactus.dk 05-02-2008 18:02 >>> > Hi Stuart et al > > No there is no GUI, just code. > I have some code like this. It add rows but will not save them to the database table: > > VrsSourceTableAdapters.DataTableKundeTableAdapter kundeAdapterS = > new VrsSourceTableAdapters.DataTableKundeTableAdapter(); > VrsSource.DataTableKundeDataTable kunderS; > > VrsTargetTableAdapters.DataTableKundeTableAdapter kundeAdapterT = > new VrsTargetTableAdapters.DataTableKundeTableAdapter(); > VrsTarget.DataTableKundeDataTable kunderT; > > kunderS = kundeAdapterS.GetDataVrsKunder(); > kunderT = kundeAdapterT.GetDataVrsKunder(); > > foreach (VrsSource.DataTableKundeRow kundeRowS in kunderS) > { > Console.WriteLine("Kunde: " + kundeRowS.navn + ""); > Console.WriteLine(" Kundenr: " + kundeRowS.kundeNr + ""); > // Mark row as modified. > kundeRowS.SetModified(); > kunderT.ImportRow(kundeRowS); > } > > Console.WriteLine("s: " + kunderS.Count.ToString()); > Console.WriteLine("t: " + kunderT.Count.ToString()); > > kundeAdapterT.FillVrsKunder(kunderT); > > Target table is residing in MSDE. > Count of s returns the count of records to add. > Count of t returns existing records + count of records to add. > > What am I missing? > > /gustav > > > >>> stuart at lexacorp.com.pg 05-02-2008 00:06:55 >>> > Do you mean have the user physically browse through the rows looking for specific records? > > If that is the case, I would probably go with a DatagridView bound to the source data. > When the user selects a row (double click, highlight and click a > button or whatever), read the row data and feed it to a TableAdapter.Insert on the target table. > > > On 4 Feb 2008 at 18:41, Gustav Brock wrote: > > > Hi all > > > > I have created two tableadapters, a source and a target, and need to > > browse through the source looking for rows and, when a row meeting > > some conditions is found, copy this to the target. What is the best > > method? > > > > /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 10:59:30 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 07 Feb 2008 17:59:30 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 11:51:14 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 09:51:14 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: It clears the DataRow collection of the datatable. Charlotte -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 12:07:54 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 10:07:54 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Feb 7 17:00:56 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 00:00:56 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From cfoust at infostatsystems.com Thu Feb 7 19:16:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 7 Feb 2008 17:16:26 -0800 Subject: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter In-Reply-To: References: Message-ID: I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 8 01:58:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 08:58:14 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte Thanks for that explanation, I can see why you do it this way. My situation is somewhat different as no data will be live - the source is an Access mdb permanently linked to the SQL Server - and the import will be run at regular intervals. Thus, should a row or two be lost during an import they will be fetched at the next run. As for the array compare, I will check out your idea of a temp table. /gustav >>> cfoust at infostatsystems.com 08-02-2008 02:16 >>> I think the speed depends on how you use it and whether your BE is Access or SQL Server. Doing it this way handles those pesky concurrency issues. Plus, we don't know whether the row is going to be updated or inserted when we try the update call. The ImportAdapter we call in the routine adds a handler for the RowUpdated event of the DataAdapter. When the event fires, we trap any OleDbException and decide what to do about it. If an update call failed, we try creating a dataset clone and attempting to LoadDataRow using an ItemArray of the items in the row. If that works, we call the ImportAdapter to update the row from the clone dataset and we set the row's UpdateStatus to SkipCurrentRow. If we tried an insert and it failed with a duplicatevalue exception, we know the row exists, so we acceptchanges on it, setModifed and then call the ImportAdapter to update the row then we set the row's UpdateStatus to SkipCurrentRow. And if you're updating live data, you don't have much choice because someone else could change it between the time you accepted a changed row and the time it was actually written back to the DB. I don't know of a way to directly compare ItemArrays, but that doesn't mean one doesn't exist. I can see why you can't cast them as strings though, since they can hold any kind of object. What about importing one ItemArray into a temp datatable and then trying to update it with the other one? If the update succeeds, they don't match. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 3:01 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From Gustav at cactus.dk Fri Feb 8 10:41:39 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 08 Feb 2008 17:41:39 +0100 Subject: [dba-VB] Copy tables: Update or insert rows in a DataTableAdapter from another DataTableAdapter Message-ID: Hi Charlotte and Stuart et al The hash code of a row cannot be used as it is based on the parent (name of DateTable or DataSet object) and the position of the row in this, not the content. And ToString of the ItemArray and other objects just returns the name of the object, not the content or value of it. However, I located a very simple method to compare two arrays with "normal" content - not BLOBS or binaries - without having to code loops and so on. Once again, the .Net framework came to rescue - this time with Concat which (also) is able to concatenate the rows of an array. So: // DataTableAdapter to copy from. VrsSourceTableAdapters.DataTableOrdreTableAdapter ordreSAdapter = new VrsSourceTableAdapters.DataTableOrdreTableAdapter(); VrsSource.DataTableOrdreDataTable ordreS; // DataTableAdapter to copy to. VrsTargetTableAdapters.DataTableOrdreTableAdapter ordreTAdapter = new VrsTargetTableAdapters.DataTableOrdreTableAdapter(); VrsTarget.DataTableOrdreDataTable ordreT; // DataTable for source. ordreS = ordreSAdapter.GetDataVrsOrdrer(); // DataTable for target. ordreT = ordreTAdapter.GetDataVrsOrdrer(); // Read each row from the source rows. // Update those found in the target table. // Append those not found in the target table. // Variable to hold primary key to locate. Int32 key; // Create row to hold a found row in the target. VrsTarget.DataTableOrdreRow foundRow = null; // Variables to hold hash codes of row contents. int hashSource; int hashTarget; foreach (VrsSource.DataTableOrdreRow ordreSRow in ordreS) { // Value of primary key to locate. key = ordreSRow.ordreNr; // Find a matching row in the target. foundRow = ordreT.FindByOrdreNr(key); if (foundRow == null) { // Row is not found. // Set the RowState of the source row as Added. ordreSRow.SetAdded(); // Append it to the target preserving the RowState. ordreT.ImportRow(ordreSRow); } else { // Row is found. Console.WriteLine(" Found: " + key.ToString()); // Calculate hash code to see if source row and target row match. hashSource = String.Concat(ordreSRow.ItemArray).GetHashCode(); hashTarget = String.Concat(foundRow.ItemArray).GetHashCode(); Console.WriteLine(" - Hash: " + hashSource.ToString() + " - " + hashTarget.ToString()); if (hashSource != hashTarget) { // The source row is updated. Console.WriteLine(" Modified OrdreNr: " + ordreSRow.ordreNr + ""); // Copy full content from source row to target row. // This sets RowState of the target row to Modified. foundRow.ItemArray = ordreSRow.ItemArray; // Do NOT call AcceptChanges here as this would clear property RowState. } } } // Write back to the database table the updated/appended rows of target DataTable. ordreTAdapter.Update(ordreT); Of course, if you have juxtaposed columns with similar content like: Val1 Val2 Concatenated string 3 44 344 34 4 344 just concatenating these may in some cases fail as the right column shows, but that is not the case for my current task. So now I only update modified records and append new records leaving the bunch of not modified records untouched! /gustav >>> Gustav at cactus.dk 08-02-2008 00:00 >>> Hi Charlotte OK, now I see. Sounds pretty as the exact same task I have to carry out. But isn't that terrible slow? I mean, for each row to import you call the Update method of the DataTableAdapter which causes a roundtrip to the database server. I was looking for a method to update the complete DateTable (or DataSet) and then save the complete collection of updated/appended rows in on go. However, right now my code saves the complete DataTable as all existing rows are updated. I'm looking for method to check if a row actually is changed or not. As the target and source rows come from two different DataTableAdapters I cannot use Equal. It seems I have to compare the content of the rows to look for a match. This doesn't seem to work: targetRow.ItemArray == sourceRow.ItemArray but perhaps this will: targetRow.ItemArray.ToString() == sourceRow.ItemArray.ToString() Anyway, I'm looking for a general ans simple way - without looping the fields - to compare two arrays. Any suggestions? /gustav >>> cfoust at infostatsystems.com 07-02-2008 19:07 >>> My last reply wasn't too enlightening. What's going on here is we are importing using a dataadapter to a table of the same name. In other words, we're updating an existing table and adding any new rows. The data may be from a file, a table, a dataset, or whatever, but by the time it gets to this routine, it's in a datatable. Normally, we're importing from XML. We create a copy of the table passed in using the Clone method so we have the structure automatically. For each datarow in the table passed in, we clear the clone's datarow collection and import the row into the clone. We then acceptchanges to get the row solidly into the clone table and the SetModified to mark it as changed. Then we pass that clone with its single modified row to the update method of the dataadapter, which takes care of shoving it into the existing table we're updating. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 07, 2008 8:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Copy tables: Update or insert rows ina DataTableAdapter from another DataTableAdapter Hi Charlotte Thanks. Yes, my task is obviously slightly more complicated ... and, of course, in most situations you operate on one database only. I can see that you use the ImportRow method too. And as I read it, you copy a row by clearing the target first and then importing the source/remote row? But what does method Clear do here? As far as I know, Clear "erases" the row and leave it - it does not delete it. /gustav >>> cfoust at infostatsystems.com 07-02-2008 17:31 >>> The thing is, you aren't just copying a table. It sounds like you're only making a copy if one doesn't exist. Otherwise, you're making sure the records are in sync. That's a bit more complicated than just copying a table, so I can see why you didn't find any code specifically for that. A datatable has a Copy method, and that would be the logical way to copy a table, if that's all you were doing. Here's an example of an approach we use when importing a table. The ImportAdaptor method it calls simply returns an instantiated OleDb.OleDbDataAdapter that has already retrieved a pre-build dataadapter for handing that table. Maybe it will give you some ideas: Public Sub ImportTable(ByVal table As System.Data.DataTable) Implements IMiscData.ImportTable Dim da As OleDb.OleDbDataAdapter = ImportAdapter(table.TableName) Dim dsTmp As DataSet = table.DataSet.Clone For Each rowRemote As DataRow In table.Rows dsTmp.Tables(0).Rows.Clear() dsTmp.Tables(0).ImportRow(rowRemote) dsTmp.Tables(0).Rows(0).AcceptChanges() dsTmp.Tables(0).Rows(0).SetModified() da.Update(dsTmp.Tables(0)) Next dsTmp.Dispose() End Sub Charlotte Foust From askolits at nni.com Fri Feb 8 15:35:40 2008 From: askolits at nni.com (John Skolits) Date: Fri, 8 Feb 2008 16:35:40 -0500 Subject: [dba-VB] VBA Excel Validation Message-ID: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits From shamil at users.mns.ru Sat Feb 9 04:26:38 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 13:26:38 +0300 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <019f01c86a9a$8d28ac60$0f01a8c0@officexp> Message-ID: <000f01c86b06$40ef9cc0$6401a8c0@nant> Hello John, Excel.Worksheet object has several events related to Excel.Range: Event Change(Target As Range) Event SelectionChange(Target As Range) Event BeforeDoubleClick(Target As Range, Cancel As Boolean) Event BeforeRightClick(Target As Range, Cancel As Boolean) You can try to explore and use these events... Excel.Workbook object has a couple of useful events to implement validation on whole worksheet/workbook level: Event BeforeSave(SaveAsUI As Boolean, Cancel As Boolean) Event BeforeClose(Cancel As Boolean) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 12:36 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] VBA Excel Validation This is more of an excel question but maybe someone can help. Is there a way to do cell validation in Excel. Something like an OnExit event where I can check a value after it's entered? John Skolits _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From askolits at nni.com Sat Feb 9 09:25:35 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:25:35 -0500 Subject: [dba-VB] VBA Excel Validation In-Reply-To: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <001501c86b30$04e11040$0202fea9@LaptopXP> Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub From ssharkins at gmail.com Sat Feb 9 09:26:33 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Sat, 9 Feb 2008 10:26:33 -0500 Subject: [dba-VB] VBA Excel Validation References: <000f01c86b06$40ef9cc0$6401a8c0@nant> Message-ID: <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? From askolits at nni.com Sat Feb 9 09:33:34 2008 From: askolits at nni.com (John Skolits) Date: Sat, 9 Feb 2008 10:33:34 -0500 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001501c86b30$04e11040$0202fea9@LaptopXP> Message-ID: <001601c86b31$229af7d0$0202fea9@LaptopXP> It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Sat Feb 9 10:20:27 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 9 Feb 2008 19:20:27 +0300 Subject: [dba-VB] RRESOVED! E: VBA Excel Validation In-Reply-To: <001601c86b31$229af7d0$0202fea9@LaptopXP> Message-ID: <000001c86b37$ae6f1d30$6401a8c0@nant> Congrats! :) -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 6:34 PM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] RRESOVED! E: VBA Excel Validation It was actually working at the workbook level. I hadn't closed the first message box while I was trying the other sheets and the message box went to the background (I've never seen this before and can't reproduce it) Doesn't really matter. It's working, thanks. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Skolits Sent: Saturday, February 09, 2008 10:26 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VBA Excel Validation Shamil, I may be asking you a few questions over the next few days as I'm working on a new project so if they are basic questions, bare with me. I was successful in using the BeforeDoubleClick event on a 'sheet', but want it to work for 'every sheet' without having to add the code to every sheet. I tried the following at the 'workbook' level for testing and hoped it would be global across all sheets. Am I thinking about this in the wrong way? Here is the code: Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean) MsgBox "The Target Is " & Target MsgBox "The Target Name Is " & Target.AddressLocal End Sub _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Feb 10 04:18:26 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:18:26 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 04:25:18 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 11:25:18 +0100 Subject: [dba-VB] Installing SQL Server 2005 Management Studio after Visual Studio 2008 Message-ID: Hi all Found this tip which can save you a lot of time and lost hair: http://codingreflection.com/wordpress/?p=371 should you receive the message: "None of the selected features can be installed or upgraded." If so, use this command to run the install where d is your cd drive: d:\setup.exe SKUUPGRADE=1 /gustav From Gustav at cactus.dk Sun Feb 10 08:09:12 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 15:09:12 +0100 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP Message-ID: Hi all Well, they (MS) are not kidding: http://blogs.msdn.com/somasegar/archive/2007/12/09/visual-studio-and-sql-server-2008.aspx For Visual Studio 2008 to support SQL Server 2008, we will be delivering a patch to coincide with the next CTP of SQL Server 2008. which raises the logical question: When is next CTP of SQL Server 2008 coming out? ... Monday, January 21, 2008 1:53 PM by Somasegar The next CTP of SQL Server 2008 will likely come out towards the end of Feburary - in time for the "VS2008, Windows Server 2008 and SQL Server 2008" launch. Good timing? /gustav >>> Gustav at cactus.dk 10-02-2008 11:18 >>> Hi al How odd is this? I just took the time to install SQL Server 2008 Express CTP and VS2008 on a new machine (Vista) to enjoy a brave new world. But as soon you attempt to connect to the server, this message pops: "This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported." They must be kidding ... even an add-on for VS2005 is available: http://www.microsoft.com/downloads/details.aspx?FamilyID=e1109aef-1aa2-408d-aa0f-9df094f993bf&displaylang=en How odd is this? VS2008 ships with the SQL Server 2005 Express but still. Any ideas on how to get it to accept SQL Server 2008 CTP? /gustav From Gustav at cactus.dk Sun Feb 10 11:14:00 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 10 Feb 2008 18:14:00 +0100 Subject: [dba-VB] Visual Studio 2008: MSDTC on server 'servername' is unavailable (Solution) Message-ID: Hi all When you try to connect to a linked database on a remote server, you will probably succeed. However, when you try to preview the data (using the GetData.. method), you may receive this message just as data are to be retrieved: MSDTC on server 'servername' is unavailable I found the solution here: http://geekswithblogs.net/narent/archive/2006/10/09/93544.aspx Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Run MS DTC If you have the application and the SQL Server Data base in two different machines you must do that also Control Panel > Adminstrative Tools > Component Services > Computers > (right click) My Computer > Properties > MS DTC (TAB) > allow remote access In my case, the MS DTC service was running - I just had to touch it as described to get it working. Somewhat strange, I think, but who cares. Also, I modified the hosts and lmhosts.sam files to include the name lookup of the remote server as this is not a server with a public URL, but I'm not sure if that really is necessary as VS previously was perfectly able to preview a table of a normal database (but not of a linked) on that same server. hosts file: xxx.xxx.xxx.xxx servername # Description of server lmhosts.sam file: xxx.xxx.xxx.xxx servername #PRE #Description of server /gustav From accessd at shaw.ca Sun Feb 10 12:33:23 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sun, 10 Feb 2008 10:33:23 -0800 Subject: [dba-VB] Visual Studio 2008 and SQL Server 2008 CTP In-Reply-To: References: Message-ID: Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; Hi Jim True, but indeed I suspect this issue to be true also if the SQL Server 2008 is installed on a remote machine. VS2008 seems to have very few issues running on Vista Business which is what I use. /gustav >>> accessd at shaw.ca 10-02-2008 19:33 >>> Very strange Gustav... but Vista is still just a desktop app and is not a server class OS...? Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Sunday, February 10, 2008 2:18 AM To: dba-sqlserver at databaseadvisors.com; References: <000f01c86b06$40ef9cc0$6401a8c0@nant> <007f01c86b30$59bb79c0$4b3a8343@SusanOne> Message-ID: <020e01c86c2f$1d233b10$0f01a8c0@officexp> Thanks for getting back to me. I ended up using one of the events to do a validation. But I may use your recommendation for something else. Thanks, John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Saturday, February 09, 2008 10:27 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VBA Excel Validation Excel has a Data Validation feature -- do you need something more flexible than that? Susan H. > > This is more of an excel question but maybe someone can help. > > Is there a way to do cell validation in Excel. > Something like an OnExit event where I can check a value after it's > entered? _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From accessd at shaw.ca Sat Feb 16 13:52:51 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Sat, 16 Feb 2008 11:52:51 -0800 Subject: [dba-VB] New Library on the DBA site In-Reply-To: <003d01c870a3$a11e3230$4b3a8343@SusanOne> References: <001201c8709f$b7bb5e40$0300a8c0@danwaters> <003d01c870a3$a11e3230$4b3a8343@SusanOne> Message-ID: Hi All: There is a new Library section added to the DBA (http://www.databaseadvisors.com) web site. The section is split into 3 modules, one for books, one for articles and one for Podcast. This section is designed to high-lite the creations of list members. The present pages are by no means current or complete and are but a sample of what our members have created. If you have more links and contribution please email me, Jim Lawrence at webmaster at databaseadvisors.com Regards Jim From fhtapia at gmail.com Mon Feb 18 17:28:55 2008 From: fhtapia at gmail.com (Francisco Tapia) Date: Mon, 18 Feb 2008 15:28:55 -0800 Subject: [dba-VB] Building something quick 'n dirty Message-ID: I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From Gustav at cactus.dk Tue Feb 19 01:26:19 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Tue, 19 Feb 2008 08:26:19 +0100 Subject: [dba-VB] Building something quick 'n dirty Message-ID: Hi Francisco Given that time frame, CodeCharge comes to my mind: http://www.yessoftware.com/index2.php /gustav >>> fhtapia at gmail.com 19-02-2008 00:28 >>> I need a quick Web application... ala Access. The main menu should include the following Links to a page that allows me to add/edit Questions, Names, Companies, and finally Add the Survey Questions. I have my demo in Access and they want the webpage ready tomorrow... a quick and dirty page would make all the difference, Any way to get this off the ground super quick ala a quick wizard? :D I know i'm grasping at straws but.. any help is appreciated. -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From dwaters at usinternet.com Tue Feb 19 14:59:21 2008 From: dwaters at usinternet.com (Dan Waters) Date: Tue, 19 Feb 2008 14:59:21 -0600 Subject: [dba-VB] Any Students Out There? Message-ID: <004601c8733a$4ce7dba0$0300a8c0@danwaters> >From USA Today: Microsoft is giving students free access to its most sophisticated tools for writing software and making media-rich websites, a move that intensifies its competition with Adobe Systems and could challenge open source software's popularity. The Redmond-based software maker said late Monday it will let students download Visual Studio Professional Edition, a software development environment; Expression Studio, which includes graphic design and website and hybrid Web-desktop programming tools; and XNA Game Studio 2.0, a video game development program. From Gustav at cactus.dk Wed Feb 20 13:38:50 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 20 Feb 2008 20:38:50 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From Gustav at cactus.dk Thu Feb 21 06:33:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 21 Feb 2008 13:33:41 +0100 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Message-ID: Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav From accessd at shaw.ca Thu Feb 21 14:52:57 2008 From: accessd at shaw.ca (Jim Lawrence) Date: Thu, 21 Feb 2008 12:52:57 -0800 Subject: [dba-VB] How to set password for a DataTable(Adapter)'s connection? In-Reply-To: References: Message-ID: <0FF1B8B3E7B040B88549BFEE9E780C48@creativesystemdesigns.com> Hi Gustav: That is a helpful piece of information. Jim -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 4:34 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] How to set password for a DataTable(Adapter)'s connection? Hi all OK, I found out. The DataTableAdapter has a Connection which has a ConnectionString property, and you can modify that using the SqlConnectionStringBuilder. Here is for my targetDataTableAdapter: Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); // Define password. string password = (string)"YourSecretPassword"; // Retrieve connection string. SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(); sqlConnectionStringBuilder.ConnectionString = targetDataTableAdapter.Connection.ConnectionString; // Apply password to connection string. sqlConnectionStringBuilder.Password = password; // Apply the modifed connection. targetDataTableAdapter.Connection = new SqlConnection(sqlConnectionStringBuilder.ToString()); Console.WriteLine(targetDataTableAdapter.Connection.ConnectionString); /gustav >>> Gustav at cactus.dk 20-02-2008 20:38 >>> Hi all Is it possible at runtime to set the password for the connection when you open a DataTableAdapter? I have code like this: // DataTableAdapter to copy from. RemoteTableAdapters.CompanyTableAdapter sourceDataTableAdapter = new RemoteTableAdapters.CompanyTableAdapter(); Remote.CompanyDataTable sourceDataTable; // DataTableAdapter to copy to. LocalTableAdapters.CompanyTableAdapter targetDataTableAdapter = new LocalTableAdapters.CompanyTableAdapter(); Local.CompanyDataTable targetDataTable; // DataTable for source. sourceDataTable = sourceDataTableAdapter.GetData(); // DataTable for target. targetDataTable = targetDataTableAdapter.GetData(); If the underlying database connection needs a password, the code fails at the line with GetData(). Would I need to go all the way back to read the ConnectionString, modify this, and reapply? How? Or is there a more clever method? At best like: targetDataTableAdapter.Connection.SetPassword("secret"); /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 01:35:36 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 08:35:36 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From cfoust at infostatsystems.com Fri Feb 22 09:49:30 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 22 Feb 2008 07:49:30 -0800 Subject: [dba-VB] DataSet, view deleted rows In-Reply-To: References: Message-ID: You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 22 10:04:48 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 22 Feb 2008 17:04:48 +0100 Subject: [dba-VB] DataSet, view deleted rows Message-ID: Hi Charlotte That is of course more direct for single values. So much to learn ... /gustav >>> cfoust at infostatsystems.com 22-02-2008 16:49 >>> You can also read the data from a deleted DataRow on a field by field basis, but it's a little different: If myRow.RowState = DataRowState.Deleted Then strVal = myRow.Item("Field1", DataRowVersion.Original).ToString Else strVal = myRow.Field1 End If We use this when we need to do something like renumber a sequence value in an array of DataRows where one or more has been deleted. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 21, 2008 11:36 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] DataSet, view deleted rows Hi all I browsed this tip from FMS and noticed at the bottom a way to view deleted rows of a DataSet should you wish to: http://www.fmsinc.com/free/NewTips/NET/NETtip56.asp 'in order to access the values from the deleted row you can create a filtered dataview Debug.WriteLine("Retrieve the values of deleted rows") Dim dv As New DataView(dt, "", "", DataViewRowState.Deleted) For Each drv As DataRowView In dv Debug.WriteLine("ID: " & drv.Item("ID").ToString & _ ", Name: " & drv.Item("Name").ToString) Next /gustav From Gustav at cactus.dk Wed Feb 27 08:18:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 15:18:41 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Johncliviger at aol.com Wed Feb 27 10:39:25 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 11:39:25 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: How about the app.config in the solution explorer johnc From Gustav at cactus.dk Wed Feb 27 11:15:58 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:15:58 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Well, that is what I thought. But it is read-only. Has to be edited manually via the GUI. /gustav >>> Johncliviger at aol.com 27-02-2008 17:39 >>> How about the app.config in the solution explorer johnc From Johncliviger at aol.com Wed Feb 27 11:50:59 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Wed, 27 Feb 2008 12:50:59 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Wed Feb 27 11:54:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Wed, 27 Feb 2008 18:54:47 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John Yes, just use my normal address: gustav at cactus.dk /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Gustav at cactus.dk Thu Feb 28 04:00:21 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 11:00:21 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc From Johncliviger at aol.com Thu Feb 28 04:50:46 2008 From: Johncliviger at aol.com (Johncliviger at aol.com) Date: Thu, 28 Feb 2008 05:50:46 EST Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Gustav mmmm...not sure I've got an answer....let me poke around in some other stuff I've got. johnc From BarbaraRyan at cox.net Thu Feb 28 06:13:09 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:13:09 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: Message-ID: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From BarbaraRyan at cox.net Thu Feb 28 06:49:25 2008 From: BarbaraRyan at cox.net (Barbara Ryan) Date: Thu, 28 Feb 2008 07:49:25 -0500 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <012501c87a03$48a088b0$0a00a8c0@PCRURI35> Message-ID: <012701c87a08$593b88a0$0a00a8c0@PCRURI35> Sorry... I just realized that this is the VB mail list...Barb -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Barbara Ryan Sent: Thursday, February 28, 2008 7:13 AM To: 'Discussion concerning Visual Basic and related programming issues.' Subject: Re: [dba-VB] VS2005: Storing application settings I'm just getting started in ASP.NET...but, will this example help?....Barb Setting Values at Run Time Some applications are built with administration tools that can update the application's settings. In ASP.NET 2.0, we can modify settings in the web.config in our code. This is something we would want to do in response to a button's click event. The sample code below shows how easy it is to modify an application setting in ASP.NET 2.0. Listing 8 Protected Sub btnUpdateSetting_Click(ByVal sender AsObject, ByVal e As System.EventArgs) _ Handles btnUpdateSetting.Click Dim cfg As Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~") Dim setting As KeyValueConfigurationElement = _ CType(cfg.AppSettings.Settings("MySetting"),KeyValueConfigurationElement) If Not setting Is Nothing Then setting.Value = "New Value Setting" cfg.Save() End If End Sub -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 5:00 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi John I had a look but unfortunately it seems as your demo form only deals with the settings for the form. What I am after is an option to - from code - not only read but also write the application settings as shown on tab Settings when you open the project's Properties from menu Project (bottom entry). These can be read easily but only written to if you attack the underlying XML file which I don't like - I mean, if the settings are read-only it is for a reason, though dull. So I wondered what others do to persistently save various application settings? /gustav >>> Johncliviger at aol.com 27-02-2008 18:50 >>> Gustav I may have an vb.net 2005 app that contains the settings info you're after. It needs sending as an attachement. Got an address? johnc _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Thu Feb 28 10:01:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 08:01:26 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Thu Feb 28 11:02:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 28 Feb 2008 18:02:08 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From cfoust at infostatsystems.com Thu Feb 28 11:28:37 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 28 Feb 2008 09:28:37 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Feb 29 07:22:06 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:22:06 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte et al OK, I'm a child of VS2005, and when creating data sources the wizard kindly asks if you wish to save the connection strings in a file. Yes please, and that file happens to be app.config which you can read and write via the GUI. Now I realize that this file has entries for application settings as well as user settings where the main difference is that the application settings are read-only during runtime. This, of course, limits the value of using the application settings as you may have a need to store or edit application setting entries during runtime. I don't like to reinvent the wheel so I wondered if any method exists to circumvent this limitation other than to create a separate system as you have done. The only method I have seen is to open the app.config XML file directly as any other XML file: http://www.ryanfarley.com/blog/archive/2004/07/13/879.aspx To complicate matters, an advice is _not_ to do that because - as I mentioned previously - if the app.config file is read-only, it might be for a reason. That reason is explained here: http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav >>> cfoust at infostatsystems.com 28-02-2008 18:28 >>> OK, you've totally lost me. We don't reference either of those files, and why should we? All (or virtually all) of the contents are created as we build the application. The only time we modify our app.config is to handle a DataDynamics licensing issue on our onw workstations. Geeks notwithstanding, settings only apply at runtime, and we can control those nicely with xml files. We store our connection strings in an xml file, not in app.config, and read them when we need them. Obviously, userIDs and passwords are NOT stored in the xml file. I still have the feeling we're talking about two different things here. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, February 28, 2008 9:02 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi Charlotte It is the app.config xml file for application settings like Connection strings and so on: C:\...\Visual Studio 2005\Projects\\\app.config It holds the entries from the menu Project, Properties pane, tab Settings. Nothing wrong with XML files. It's just that it seems that this file is for VS's use, so don't tamper with it. If you reference System.Configuration you can easily read from it via code, and methods exists for editing and saving values for _users_, however nothing can be saved for the _application_: http://geekswithblogs.net/akraus1/articles/64871.aspx /gustav >>> cfoust at infostatsystems.com 28-02-2008 17:01 >>> Are you talking about settings for Visual Studio or settings for an application? We use XML files for storing application settings (not VS settings), Gustav. I don't know why you characterize it as clumsy, and we don't "attack" any xml files. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Wednesday, February 27, 2008 6:19 AM To: dba-vb at databaseadvisors.com Subject: [dba-VB] VS2005: Storing application settings Hi all How do you store application settings? I've noticed the nice pane with the tab "Settings" for manually doing this, but it is read-only from code. Of course you can step down and attack the xml file storing the data, but I find that a bit clumsy. /gustav From Gustav at cactus.dk Fri Feb 29 07:58:40 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 14:58:40 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From cfoust at infostatsystems.com Fri Feb 29 10:00:48 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 08:00:48 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: References: Message-ID: I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From ssharkins at gmail.com Fri Feb 29 10:40:48 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 11:40:48 -0500 Subject: [dba-VB] VS2005: Storing application settings References: Message-ID: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, but > I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From cfoust at infostatsystems.com Fri Feb 29 11:29:51 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 29 Feb 2008 09:29:51 -0800 Subject: [dba-VB] VS2005: Storing application settings In-Reply-To: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: Storing stuff in the registry is definitely discouraged in dotNet, Susan. And more and more, the registry is being locked down by system administrator. We started to run into problems with that in our extant Access applications. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Susan Harkins Sent: Friday, February 29, 2008 8:41 AM To: Discussion concerning Visual Basic and related programming issues. Subject: Re: [dba-VB] VS2005: Storing application settings > How do you store application settings? > > I've noticed the nice pane with the tab "Settings" for manually doing > this, but it is read-only from code. > Of course you can step down and attack the xml file storing the data, > but I find that a bit clumsy. =====I'm not sure if VS works the same way as Access, but in Access, I store individual settings in the registry. Susan H. From Gustav at cactus.dk Fri Feb 29 11:31:04 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 29 Feb 2008 18:31:04 +0100 Subject: [dba-VB] VS2005: Storing application settings Message-ID: Hi Charlotte Thanks. I'll stick to that method. /gustav >>> cfoust at infostatsystems.com 29-02-2008 17:00 >>> I don't know if it's THE answer, but it's the one we use. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, February 29, 2008 5:59 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] VS2005: Storing application settings Hi all Again, pressing Send helps assimilation. Just browsed to the last paragraph of the link. Calling: Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationDat a) returns on my machine: "C:\\Documents and Settings\\All Users\\Application Data" Is that the answer? /gustav >>> Gustav at cactus.dk 29-02-2008 14:22 >>> http://www.interact-sw.co.uk/iangblog/2004/11/25/savingconfig where the author claims that one should never write files into the Program Files folder ..(!) .. but use the Application Data folder of the user. That may be true, and I sure want to behave, but the next question is then: Where to store config files and such common for all users? Would that be: C:\Documents and Settings\All Users\Application Data\YourApp So, where do you store your application data common for all users? /gustav From ssharkins at gmail.com Fri Feb 29 11:47:20 2008 From: ssharkins at gmail.com (Susan Harkins) Date: Fri, 29 Feb 2008 12:47:20 -0500 Subject: [dba-VB] VS2005: Storing application settings References: <037d01c87af1$dcd0af30$4b3a8343@SusanOne> Message-ID: <013201c87afb$31a5d270$4b3a8343@SusanOne> Too bad... it's an easy solution. Susan H. > Storing stuff in the registry is definitely discouraged in dotNet, > Susan. And more and more, the registry is being locked down by system > administrator. We started to run into problems with that in our extant > Access applications.