473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Navigating parent/child table

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!
Jul 21 '05 #1
0 2098

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9114
by: ahaideb | last post by:
I have a table (relation) in my database: --------------- | parent | child | --------------- | 1 | 2 | | 1 | 3 | | 2 | 4 | | 2 | 5 | | 3 | 6 |
1
1741
by: muesliflakes | last post by:
I have a Data Set with parent / child related tables and wish to show the parent rows in one data grid and the child rows in another data grid. The problem is that the parent datagrid has the ability to drill down to the child records with its own grid. How can I suppress this ability. I only want to edit children in the child datagrid,...
1
2204
by: Aaron Smith | last post by:
I have a parent table that has one child table. The parent has a single field (ID, AutoIncrement, Seed 0, Step -1 in the DataSet, Seed 1, step 1, in DataSource). The child is linked to this ID column in the parent. I have the parent fields in textboxes and the child is a DataGrid. When I add a new parent record, then go to add child records, I...
0
199
by: Mark Tait | last post by:
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...
0
8558
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row and add child grid into that row because the columns in child grid are same as parent grid and we want to align them with the cols of parent grid....
1
2765
by: Hexman | last post by:
Hello All, What I'm trying to do is update a child record using a parent-child relation. I want to find out if it is faster than than doing multiple selects. Anyways, I've created a dataset (ds), have 2 datatables (dtRC and dtST). Created the parent-child relationship with multiple columns and added the relation to the dataset. Now what...
4
1882
by: mikemiller.innova | last post by:
In Visual Studio 2005 SP1, I added a DataSet item into my project. I added 3 tables from SQL that have data and relationships. I added 2 lookup columns (lkp) to the DllVersions table in the dataset ProjectID
8
5963
by: Rick | last post by:
VS 2005 I' m setting up a parent/child datagridviews in a form. I am doing a lot of this by hand coding in order to get the feel of things. I want a change in the parent table to trigger a change in the child. Where is the best place (if I cannot set it up to be automatic through relationships) to catch the change in the parent to...
3
18689
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however, working with complex reports is tricky Assumption: Reader of this article have basic knowledge of creating data reports. Creating a Parent-Child...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.