Elip Posted November 7, 2003 Posted November 7, 2003 Hello. I�m trying to select an entry from a child row in my data set but not having any experience with data bases and the .Net DataSet I'm having some problems. The data set schema is very simple; I have a primary element named DIRECTORY which contains a name field and a file field. The file field is an element named FILE which contains its own name field and several file properties fields. So, after the data set is filled I try to access a file record in the following way. // this line works DataRow *foundDirRows[] = dataset->DIRECTORY->Select("name = '{0}'", fileInfo->Directory->Name); // assum the dir is found for this example dirRow = __try_cast<FileInfoDataset::DIRECTORYRow*>(foundDirRows[0]); // this is the problem line, it never finds the file DataRow *foundFileRows[] = dirRow->Table->Select("name = '{0}'", fileInfo->Name); If I save the data set as XML and open it in Visual Studio I can clearly see that the file entry is there and it is a child of the directory I selected. Apparently this is not the correct way to access the row associated with the file. :confused: How should I be doing this? Quote
*Experts* Nerseus Posted November 8, 2003 *Experts* Posted November 8, 2003 I've not tried this in C++, but if it's the same type of Select as other languages, you'll want to change your Select line to this: DataRow *foundDirRows[] = dataset->DIRECTORY->Select(String->Format("name = '{0}'", fileInfo->Directory->Name)); Normally the Select method's first param, a string, is the filter. The second param is a sort. It appears as though you really want to use String.Convert to piece together your filter. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
loyal Posted November 8, 2003 Posted November 8, 2003 examine this code Dim strExpr As String Dim strSort As String Dim expressions As Integer = CInt(Me.txtSearch.Text) strExpr = "MilitryNumber =" & expressions strSort = "MilitryNumber" ' Get a reference to the Main table. Dim dtEmp As DataTable = DsMain1.Tables("Main") ' Copy only the structure of the Main table in the new table. Dim newDt As DataTable = dtEmp.Clone() newDt.TableName = "MN" ' Select a subset of all Main, sorted on their MilitryNumber. Dim drows() As DataRow = dtEmp.Select(strExpr, strSort) ' Import the array of DataRows into the new table. Dim dr As DataRow For Each dr In drows newDt.ImportRow(dr) Next Me.DGMain.DataSource = newDt Me.DGMain.Refresh() Quote Gary Says: To be a good programmer, you must be good at debugging
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.