Hi - I think I'm getting very tied up here. Using Web Matrix, and have
posted in the asp.net forum, with no help unfortunately.
I have a table, which has a parent/child relationship with itself.
It has an id, fldparentid, fldquestion field.
I want to show the fields where the fldparentid is the same as the value
returned when someone clicks on the ros in my datagrid, in the function:
gridCategory_Se lectedIndexChan ged.
When this is clicked, the datagrid is refreshed, by getting a dataset,
where the parentid is equal to the id of the record which was clicked on
the datagrid.
This routine also calls GetParent and GetParents - which return the
parent id, and the fldquestion text - this I use to change the
commandargument of link button - the link button calls
lbUpCategory_Cl ick.
This works, but where I'm getting messed up is is this the best way to
navigate a parent/child table, and is there a better way of returning
one record, which will give me the two fields (ID and fldquestion) at
the same time (I'm calling two functions to get each of these just now).
My code is below,
Thanks for ANY help,
Mark
Function GetParent(ByVal fldparentid As Integer) As String
Dim fldparentidv as string
if fldparentid<>0 then
Dim connectionStrin g As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\dbweb \fld.mdb"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim queryString As String = "SELECT
[myTable].[fldparentid],[myTable].[fldquestion] FROM [myTable] WHERE
([myTable].[id] = " & fldparentid & ")"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Ole Db.OleDbCommand (querystring,db connection)
dbconnection.op en()
Dim reader as System.Data.Ole Db.OleDbDataRea der =
dbCommand.Execu teReader()
reader.read()
fldparentidv = reader.GetInt32 (0).ToString()
reader.close()
dbConnection.cl ose()
else
fldparentidv ="0"
end if
Return fldparentidv
End Function
Function GetParents(ByVa l fldparentid As Integer) As String
Dim fldparentids as string
if fldparentid<>0 then
Dim connectionStrin g As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\dbweb \fld.mdb"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim queryString As String = "SELECT [myTable].[fldquestion] FROM
[myTable] WHERE ([myTable].[id] = " & fldparentid & ")"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Ole Db.OleDbCommand (querystring,db connection)
dbconnection.op en()
Dim reader as System.Data.Ole Db.OleDbDataRea der =
dbCommand.Execu teReader()
reader.read()
fldparentids = reader.GetStrin g(0).ToString()
reader.close()
dbConnection.cl ose()
else
fldparentids ="Home"
end if
Return fldparentids
End Function
Sub gridCategory_Se lectedIndexChan ged(sender As Object, e As EventArgs)
dim gi as string =
CStr(gridCatego ry.DataKeys(gri dCategory.Selec tedIndex))
dim i as integer =
CInt(gridCatego ry.DataKeys(gri dCategory.Selec tedIndex))
gridCategory.Da taSource=GetCat sWithParent(i)
gridCategory.Da taBind()
lbUpCategory.co mmandargument=G etParent(i)
lbUpCategory.te xt=GetParents(i )
label4.text=Get Parent(i)
End Sub
Sub lbUpCategory_Cl ick(sender As Object, e As EventArgs)
gridCategory.Da taSource=GetCat sWithParent(lbU pCategory.comma ndargument)
gridCategory.Da taBind()
dim i as integer = lbUpCategory.co mmandargument
lbUpCategory.co mmandargument=G etParent(i)
lbUpCategory.te xt=GetParents(i )
label4.text=Get Parent(i)
End Sub
Mark Tait
ma**@fixitks.co .uk
www.fixitks.co.uk
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!