|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple way of finding whether a certain value is in a DataSet columnHi,
is there a simple and elegant way of finding whether a given string value is already present in DataSet column? Although I may do this using a For statement or something similar, I'd like to avoid using cycles. I'm looking for a method of DataSet, DataSet.Table etc., if there is any. Unfortunately, I was not able to find anything like that. Second question: I also need to find the row to which a given row of a DataGridView is bound. Again, I would prefer a simple method-based solution, if it exists... :) Thanks very much for any help... With regards nvx It sounds like you're asking for the features of a SQL query engine. That's
not supported in ADO.NET (at least not yet). There is nothing to stop you from walking the DataSet Table(n).Rows(n).Item(n) and testing... -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "nvx" <nvx2***@hotmail.com> wrote in message news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... > Hi, > is there a simple and elegant way of finding whether a given string > value is already present in DataSet column? Although I may do this > using a For statement or something similar, I'd like to avoid using > cycles. I'm looking for a method of DataSet, DataSet.Table etc., if > there is any. Unfortunately, I was not able to find anything like > that. > > Second question: > I also need to find the row to which a given row of a DataGridView is > bound. Again, I would prefer a simple method-based solution, if it > exists... :) > > Thanks very much for any help... > > With regards > nvx > Look at DataViews.
private void button1_Click(object sender, EventArgs e) { DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", null, DataViewRowState.CurrentRows); if (view.Count > 0) MessageBox.Show("USA exists"); foreach (DataRowView rowView in view) { DSNorthwind.CustomerRow customerRow = rowView.Row as DSNorthwind.CustomerRow; MessageBox.Show(customerRow.CompanyName, customerRow.Country); } } Show quote > news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... >> Hi, >> is there a simple and elegant way of finding whether a given string >> value is already present in DataSet column? Although I may do this >> using a For statement or something similar, I'd like to avoid using >> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if >> there is any. Unfortunately, I was not able to find anything like >> that. >> >> Second question: >> I also need to find the row to which a given row of a DataGridView is >> bound. Again, I would prefer a simple method-based solution, if it >> exists... :) >> >> Thanks very much for any help... >> >> With regards >> nvx >> > > I like that a lot better...
-- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ Visit www.hitchhikerguides.net to get more information on my latest book: Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ----------------------------------------------------------------------------------------------------------------------- "Jim Rand" <jimr***@ix.netcom.com> wrote in message news:eAFl2EuUHHA.3592@TK2MSFTNGP06.phx.gbl... > Look at DataViews. > > private void button1_Click(object sender, EventArgs e) > { > DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", > null, DataViewRowState.CurrentRows); > if (view.Count > 0) MessageBox.Show("USA exists"); > > foreach (DataRowView rowView in view) > { > DSNorthwind.CustomerRow customerRow = rowView.Row as > DSNorthwind.CustomerRow; > MessageBox.Show(customerRow.CompanyName, customerRow.Country); > } > } > > >> news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... >>> Hi, >>> is there a simple and elegant way of finding whether a given string >>> value is already present in DataSet column? Although I may do this >>> using a For statement or something similar, I'd like to avoid using >>> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if >>> there is any. Unfortunately, I was not able to find anything like >>> that. >>> >>> Second question: >>> I also need to find the row to which a given row of a DataGridView is >>> bound. Again, I would prefer a simple method-based solution, if it >>> exists... :) >>> >>> Thanks very much for any help... >>> >>> With regards >>> nvx >>> >> >> > > Thanks a lot, both of you... I'll see what I can do with the things
you've suggested... With regards nvx Jim Rand napsal: Show quote > Look at DataViews. > > private void button1_Click(object sender, EventArgs e) > { > DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", > null, DataViewRowState.CurrentRows); > if (view.Count > 0) MessageBox.Show("USA exists"); > > foreach (DataRowView rowView in view) > { > DSNorthwind.CustomerRow customerRow = rowView.Row as > DSNorthwind.CustomerRow; > MessageBox.Show(customerRow.CompanyName, customerRow.Country); > } > } > > > > news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... > >> Hi, > >> is there a simple and elegant way of finding whether a given string > >> value is already present in DataSet column? Although I may do this > >> using a For statement or something similar, I'd like to avoid using > >> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if > >> there is any. Unfortunately, I was not able to find anything like > >> that. > >> > >> Second question: > >> I also need to find the row to which a given row of a DataGridView is > >> bound. Again, I would prefer a simple method-based solution, if it > >> exists... :) > >> > >> Thanks very much for any help... > >> > >> With regards > >> nvx > >> > > > > After a few minutes of coding I may say this DataView based algorithm
works like a charm... Thanks again... :) With regards nvx Jim Rand napsal: Show quote > Look at DataViews. > > private void button1_Click(object sender, EventArgs e) > { > DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", > null, DataViewRowState.CurrentRows); > if (view.Count > 0) MessageBox.Show("USA exists"); > > foreach (DataRowView rowView in view) > { > DSNorthwind.CustomerRow customerRow = rowView.Row as > DSNorthwind.CustomerRow; > MessageBox.Show(customerRow.CompanyName, customerRow.Country); > } > } > > > > news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... > >> Hi, > >> is there a simple and elegant way of finding whether a given string > >> value is already present in DataSet column? Although I may do this > >> using a For statement or something similar, I'd like to avoid using > >> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if > >> there is any. Unfortunately, I was not able to find anything like > >> that. > >> > >> Second question: > >> I also need to find the row to which a given row of a DataGridView is > >> bound. Again, I would prefer a simple method-based solution, if it > >> exists... :) > >> > >> Thanks very much for any help... > >> > >> With regards > >> nvx > >> > > > > Yep, and there is also DataTable.Select method that does similar wizardry -
instead of having an instance of DataView you get an array of rows. -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Jim Rand" <jimr***@ix.netcom.com> wrote in message news:eAFl2EuUHHA.3592@TK2MSFTNGP06.phx.gbl... > Look at DataViews. > > private void button1_Click(object sender, EventArgs e) > { > DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", > null, DataViewRowState.CurrentRows); > if (view.Count > 0) MessageBox.Show("USA exists"); > > foreach (DataRowView rowView in view) > { > DSNorthwind.CustomerRow customerRow = rowView.Row as > DSNorthwind.CustomerRow; > MessageBox.Show(customerRow.CompanyName, customerRow.Country); > } > } > > >> news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... >>> Hi, >>> is there a simple and elegant way of finding whether a given string >>> value is already present in DataSet column? Although I may do this >>> using a For statement or something similar, I'd like to avoid using >>> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if >>> there is any. Unfortunately, I was not able to find anything like >>> that. >>> >>> Second question: >>> I also need to find the row to which a given row of a DataGridView is >>> bound. Again, I would prefer a simple method-based solution, if it >>> exists... :) >>> >>> Thanks very much for any help... >>> >>> With regards >>> nvx >>> >> >> > > And even easier, the DataView Find, which gives back the index of the row.
http://msdn2.microsoft.com/en-gb/library/46d41xk2.aspx Or if you want a row instead of an index, DataRowCollection.find http://msdn2.microsoft.com/en-us/library/ydd48eyk.aspx Now we have again all 4 ADONET alternatives in one thread, :-) CorShow quote "Miha Markic [MVP C#]" <miha at rthand com> schreef in bericht news:3EA8A257-6033-4355-8957-F886BEE125FF@microsoft.com... > Yep, and there is also DataTable.Select method that does similar > wizardry - instead of having an instance of DataView you get an array of > rows. > > -- > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > RightHand .NET consulting & development www.rthand.com > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > "Jim Rand" <jimr***@ix.netcom.com> wrote in message > news:eAFl2EuUHHA.3592@TK2MSFTNGP06.phx.gbl... >> Look at DataViews. >> >> private void button1_Click(object sender, EventArgs e) >> { >> DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", >> null, DataViewRowState.CurrentRows); >> if (view.Count > 0) MessageBox.Show("USA exists"); >> >> foreach (DataRowView rowView in view) >> { >> DSNorthwind.CustomerRow customerRow = rowView.Row as >> DSNorthwind.CustomerRow; >> MessageBox.Show(customerRow.CompanyName, customerRow.Country); >> } >> } >> >> >>> news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... >>>> Hi, >>>> is there a simple and elegant way of finding whether a given string >>>> value is already present in DataSet column? Although I may do this >>>> using a For statement or something similar, I'd like to avoid using >>>> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if >>>> there is any. Unfortunately, I was not able to find anything like >>>> that. >>>> >>>> Second question: >>>> I also need to find the row to which a given row of a DataGridView is >>>> bound. Again, I would prefer a simple method-based solution, if it >>>> exists... :) >>>> >>>> Thanks very much for any help... >>>> >>>> With regards >>>> nvx >>>> >>> >>> >> >> > Many thanks, guys... I just hope I won't forget all this additional
info untill I need it. ;) nvx Cor Ligthert [MVP] napsal: Show quote > And even easier, the DataView Find, which gives back the index of the row. > > http://msdn2.microsoft.com/en-gb/library/46d41xk2.aspx > > Or if you want a row instead of an index, DataRowCollection.find > > http://msdn2.microsoft.com/en-us/library/ydd48eyk.aspx > > > Now we have again all 4 ADONET alternatives in one thread, > > :-) > > Cor > > "Miha Markic [MVP C#]" <miha at rthand com> schreef in bericht > news:3EA8A257-6033-4355-8957-F886BEE125FF@microsoft.com... > > Yep, and there is also DataTable.Select method that does similar > > wizardry - instead of having an instance of DataView you get an array of > > rows. > > > > -- > > Miha Markic [MVP C#, INETA Country Leader for Slovenia] > > RightHand .NET consulting & development www.rthand.com > > Blog: http://cs.rthand.com/blogs/blog_with_righthand/ > > > > "Jim Rand" <jimr***@ix.netcom.com> wrote in message > > news:eAFl2EuUHHA.3592@TK2MSFTNGP06.phx.gbl... > >> Look at DataViews. > >> > >> private void button1_Click(object sender, EventArgs e) > >> { > >> DataView view = new DataView(dsNorthwind.Customer, "Country = 'USA'", > >> null, DataViewRowState.CurrentRows); > >> if (view.Count > 0) MessageBox.Show("USA exists"); > >> > >> foreach (DataRowView rowView in view) > >> { > >> DSNorthwind.CustomerRow customerRow = rowView.Row as > >> DSNorthwind.CustomerRow; > >> MessageBox.Show(customerRow.CompanyName, customerRow.Country); > >> } > >> } > >> > >> > >>> news:1171741159.716426.146660@p10g2000cwp.googlegroups.com... > >>>> Hi, > >>>> is there a simple and elegant way of finding whether a given string > >>>> value is already present in DataSet column? Although I may do this > >>>> using a For statement or something similar, I'd like to avoid using > >>>> cycles. I'm looking for a method of DataSet, DataSet.Table etc., if > >>>> there is any. Unfortunately, I was not able to find anything like > >>>> that. > >>>> > >>>> Second question: > >>>> I also need to find the row to which a given row of a DataGridView is > >>>> bound. Again, I would prefer a simple method-based solution, if it > >>>> exists... :) > >>>> > >>>> Thanks very much for any help... > >>>> > >>>> With regards > >>>> nvx > >>>> > >>> > >>> > >> > >> > > |
|||||||||||||||||||||||