|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Strongly typed dataset, sorted by dataview, how to get dataset's row index from dataview?I've created a strongly-typed dataset class (using XML), and I've instantiated it twice. The first instance is used to hold a mainframe-generated text file. The second instance is used to hold the results from a database query. Unfortunately, the text file uses a combination primary key of (branch ID, account number). However, my database has no need for branch ID- it's driven purely by account number. Of course, I've used SQL to sort my database query by account number. To sort the file's dataset, I set up the DataSet.DataTable.DefaultView.Sort = "account ASC". But in my main loop, the DataRow returned by using DataSet.DataTable.DefaultView[i].Row has lost all of the strongly-typed features that I had gained by defining an XSD class. Is there a method/property that I've missed, which will allow me to walk the objects "backwards" from the DefaultView[i] in order to get the actual source row (with strong typing) from the DataSet? Here's a sample of the structure/main loop and what I'd like to do.: public class otherClass{ //this class belongs to the database operations private MyStronglyTypedDataset dsDatabase; private int iIndex; public bool matchFound(String strAccount) { //loop based on iIndex++ to find match in dsDatabase } public MyStronglyTypedDataset.tblRow foundRow {get...} public void compareXMLds(MyStronglyTypedDataset.tblRow sourceRow) { //compares dsDatabase.mytable.Rows[iIndex] with sourceRow, //and generates report } } public class MainClass { //this is for linking the TextFile's class with the database's class MyStronglyTypedDataset ds = loadTextFileClass.resultingDataSet; for (int i=0; i<(ds.tbl.Count); i++) { //what I need is inside the asterisks below if otherClass.matchFound(ds.mytable.DefaultView[i][mykey].ToString()) otherClass.compareXMLds(**ds.mytable[i]**) } } There must be something in ADO.NET that keeps a link between the DataView's row and the underlying DataTable's row- how do I get to it? I'm wishing for something like: MyStronglyTypedDataset.tblRow sourceRow = ds.mytable.DefaultView[i].getSourceRowBack; It has crossed my mind to create a "temporary" sorted text file based off of the source file... but I'd rather not go that route- it reminds me of my Pascal days! Thanks! -Thomas H There is a property in there that points to the actual DataRow in the
DataTable. However, the is no index to tell what number that row is. In fact, the DataRow itself has no concept of where it is in the collection of rows. So you can access the underlying DataRow if you need to, but you won't be able to figure out its index in the collection via a property. Show quote "Thomas H" <T@H> wrote in message news:OjsTdQxQGHA.424@TK2MSFTNGP12.phx.gbl... > Hello everyone, here's my problem! I'm using the .NET framework v1.1... > > I've created a strongly-typed dataset class (using XML), and I've > instantiated it twice. The first instance is used to hold a > mainframe-generated text file. The second instance is used to hold the > results from a database query. Unfortunately, the text file uses a > combination primary key of (branch ID, account number). However, my > database has no need for branch ID- it's driven purely by account number. > > Of course, I've used SQL to sort my database query by account number. To > sort the file's dataset, I set up the DataSet.DataTable.DefaultView.Sort = > "account ASC". But in my main loop, the DataRow returned by using > DataSet.DataTable.DefaultView[i].Row has lost all of the strongly-typed > features that I had gained by defining an XSD class. > > Is there a method/property that I've missed, which will allow me to walk > the objects "backwards" from the DefaultView[i] in order to get the actual > source row (with strong typing) from the DataSet? > > Here's a sample of the structure/main loop and what I'd like to do.: > > public class otherClass{ > //this class belongs to the database operations > private MyStronglyTypedDataset dsDatabase; > private int iIndex; > public bool matchFound(String strAccount) > { //loop based on iIndex++ to find match in dsDatabase } > public MyStronglyTypedDataset.tblRow foundRow {get...} > public void compareXMLds(MyStronglyTypedDataset.tblRow sourceRow) > { //compares dsDatabase.mytable.Rows[iIndex] with sourceRow, > //and generates report } > } > > public class MainClass { > //this is for linking the TextFile's class with the database's class > MyStronglyTypedDataset ds = loadTextFileClass.resultingDataSet; > for (int i=0; i<(ds.tbl.Count); i++) > { > //what I need is inside the asterisks below > if otherClass.matchFound(ds.mytable.DefaultView[i][mykey].ToString()) > otherClass.compareXMLds(**ds.mytable[i]**) > } > } > > There must be something in ADO.NET that keeps a link between the > DataView's row and the underlying DataTable's row- how do I get to it? > I'm wishing for something like: > > MyStronglyTypedDataset.tblRow sourceRow = > ds.mytable.DefaultView[i].getSourceRowBack; > > It has crossed my mind to create a "temporary" sorted text file based off > of the source file... but I'd rather not go that route- it reminds me of > my Pascal days! > > Thanks! > > -Thomas H > > Thanks Marina! Since what I wanted to do is impossible, I was able to do a
"mind switch" and get the solution- casting! I had forgotten about casting... I tested this and it worked OK to get my XML types back: MyStronglyTypedDataset.tblRow realXmlRow; //outside of loop for (int i=0; i<(ds.tbl.Count); i++) { //casting brings back my strongly-typed dataset structure realXmlRow = (MyStronglyTypedDataSet.tblRow) dsMyTable.DefaultView[i].Row; //accountNumber is strongly typed and matches my database types! Console.WriteLine(realXmlRow.accountNumber); //and the iscolumnNull functions are back! if (!realXmlRow.ismarginNull) Console.WriteLine("account uses margin"); } For once, it was actually helpful to know that something was impossible (getting to the underlying DataRow object's location in the original DataSet)- you saved me a lot of time. Thanks too for understanding what I was asking! -Thomas H Show quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:usqlNU4QGHA.2176@TK2MSFTNGP10.phx.gbl... > There is a property in there that points to the actual DataRow in the > DataTable. However, the is no index to tell what number that row is. In > fact, the DataRow itself has no concept of where it is in the collection > of rows. > > So you can access the underlying DataRow if you need to, but you won't be > able to figure out its index in the collection via a property. > > "Thomas H" <T@H> wrote in message > news:OjsTdQxQGHA.424@TK2MSFTNGP12.phx.gbl... >> Hello everyone, here's my problem! I'm using the .NET framework v1.1... >> >> I've created a strongly-typed dataset class (using XML), and I've >> instantiated it twice. The first instance is used to hold a >> mainframe-generated text file. The second instance is used to hold the >> results from a database query. Unfortunately, the text file uses a >> combination primary key of (branch ID, account number). However, my >> database has no need for branch ID- it's driven purely by account number. >> >> Of course, I've used SQL to sort my database query by account number. To >> sort the file's dataset, I set up the DataSet.DataTable.DefaultView.Sort >> = "account ASC". But in my main loop, the DataRow returned by using >> DataSet.DataTable.DefaultView[i].Row has lost all of the strongly-typed >> features that I had gained by defining an XSD class. >> >> Is there a method/property that I've missed, which will allow me to walk >> the objects "backwards" from the DefaultView[i] in order to get the >> actual source row (with strong typing) from the DataSet? >> >> Here's a sample of the structure/main loop and what I'd like to do.: >> >> public class otherClass{ >> //this class belongs to the database operations >> private MyStronglyTypedDataset dsDatabase; >> private int iIndex; >> public bool matchFound(String strAccount) >> { //loop based on iIndex++ to find match in dsDatabase } >> public MyStronglyTypedDataset.tblRow foundRow {get...} >> public void compareXMLds(MyStronglyTypedDataset.tblRow sourceRow) >> { //compares dsDatabase.mytable.Rows[iIndex] with sourceRow, >> //and generates report } >> } >> >> public class MainClass { >> //this is for linking the TextFile's class with the database's class >> MyStronglyTypedDataset ds = loadTextFileClass.resultingDataSet; >> for (int i=0; i<(ds.tbl.Count); i++) >> { >> //what I need is inside the asterisks below >> if >> otherClass.matchFound(ds.mytable.DefaultView[i][mykey].ToString()) >> otherClass.compareXMLds(**ds.mytable[i]**) >> } >> } >> >> There must be something in ADO.NET that keeps a link between the >> DataView's row and the underlying DataTable's row- how do I get to it? >> I'm wishing for something like: >> >> MyStronglyTypedDataset.tblRow sourceRow = >> ds.mytable.DefaultView[i].getSourceRowBack; >> >> It has crossed my mind to create a "temporary" sorted text file based off >> of the source file... but I'd rather not go that route- it reminds me of >> my Pascal days! >> >> Thanks! >> >> -Thomas H >> >> > > |
|||||||||||||||||||||||