Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Experts*
Posted

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

"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
Posted

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()

Gary Says: To be a good programmer, you must be good at debugging

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...