473,837 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Empty child database and masterID problem

Greetings.

I have a serious problem. I have multiple sets of tables, several of
which are chained more than two tables deep. That is, I have a parent, a
child, and a great-grandchild table.

Currently, I am allowing the parent to be edited by itself. In order to
get to a child table, a user needs to select a specific parent table ID.
I have set this up using panels, and putting a drop-down list in the
first panel, with its contents drawn from the parent table. When the
user selects a parenttable.nam e, the correct parenttable.ID is sent to
the next iteration of the page, where it is used as the
childtable.pare ntID reference to populate the datagrid.

My main problem is when there are no child table entries for that parent
table ID. Without any entries, the "add entry" value for
childtable.pare ntID cannot be filled, because nothing is being drawn
from the database.

Below is the code that I have tried to implement so far:

Sub ddlSelectRegion _Click(sender As Object, e As EventArgs)
Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
Dim myCmd as New OleDbCommand("S ELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
myConn.Open()
dgCarClubInfo.D ataSource =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
Dim ltrRegionID as Literal
ltrRegionID.Tex t = ddlSelectRegion .SelectedValue
dgCarClubInfo.D ataBind()
myConn.Close()
End Sub

On the submission of the drop-down list's button, the selected value
gets extracted, and used in the SQL statement. However, if it is empty,
I need to pass that value on to the correct column in the datagrid. I
have tried to use a literal (<asp:literal /> - it uses no HTML), but the
fourth to last line always throws an error (Object reference not set to
an instance of an object). In order to populate the literal, this line
must work. That way, I can populate the "add" row's "ParentID" field
with the literal, so any additions will have the ParentID it requires.

Another problem is that I need to make this literal population fire only
when the database doesn't return any results. I have tried to find the
ASP.NET equivelents to the old rs.EOF rs.BOF methods, without success.
Any suggestions?

On another note, are there any tutorials that can show how I can have a
parent/child/grandchild/greatgrandchild datagrid (or close enough) with
every table being editable, deletable, and addable from within the same
datagrid? That is, you have "edit", "delete" and "add" buttons for every
layer of the datagrid.

TIA
....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #1
7 2020
Greetings Neo,

1- You should write a condition for if
ddlSelectRegion .SelectedItem.V alue.Equals ("") then write a different sql
statement

2- The reason you get “Object reference not set to an instance of an object”
is that you have not used the "New" keyword in instantiating the Literal
control
Dim ltrRegionID As New Literal

3- A simple way to create your expandable datagrid, is to use the
ItemDataBound event of the datagrid. This event would provide you a handle
to the datagrid item which is the analogy of a table row that contains cells.
You then loop through the cells collection of the DataGridItem, save their
values in a temporary array then rewrite an HTMtable that contains a child
datagrid bound to a child dataset. Something that uses the following code
components:

Public Class testGrid
Inherits System.Web.UI.W ebControls.Data Grid

Private Sub testGrid_ItemDa taBound(ByVal sender As Object, ByVal e As
DataGridItemEve ntArgs) Handles MyBase.ItemData Bound
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
BuildChildLayou t(e.Item)
End If

End Sub
Private Sub BuildChildLayou t(ByVal item As DataGridItem)
Dim row As DataGridItem = item
'loop through the row.Cells collection, and save their content in an
array
'remove all row.Cells
Dim newCell As New TableCell
row.Cells.Add(n ewCell)
Dim t As New Table
newCell.Control s.Add(t)
'now you have a Table (t) where you can re-write the values that you
saved above
'then add a new row, create a datagrid in it and bind it to the
child data
End Sub
End Class

--
WEBSWAPP Development Inc.
http://www.webswapp.com
"Neo Geshel" wrote:
Greetings.

I have a serious problem. I have multiple sets of tables, several of
which are chained more than two tables deep. That is, I have a parent, a
child, and a great-grandchild table.

Currently, I am allowing the parent to be edited by itself. In order to
get to a child table, a user needs to select a specific parent table ID.
I have set this up using panels, and putting a drop-down list in the
first panel, with its contents drawn from the parent table. When the
user selects a parenttable.nam e, the correct parenttable.ID is sent to
the next iteration of the page, where it is used as the
childtable.pare ntID reference to populate the datagrid.

My main problem is when there are no child table entries for that parent
table ID. Without any entries, the "add entry" value for
childtable.pare ntID cannot be filled, because nothing is being drawn
from the database.

Below is the code that I have tried to implement so far:

Sub ddlSelectRegion _Click(sender As Object, e As EventArgs)
Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
Dim myCmd as New OleDbCommand("S ELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
myConn.Open()
dgCarClubInfo.D ataSource =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
Dim ltrRegionID as Literal
ltrRegionID.Tex t = ddlSelectRegion .SelectedValue
dgCarClubInfo.D ataBind()
myConn.Close()
End Sub

On the submission of the drop-down list's button, the selected value
gets extracted, and used in the SQL statement. However, if it is empty,
I need to pass that value on to the correct column in the datagrid. I
have tried to use a literal (<asp:literal /> - it uses no HTML), but the
fourth to last line always throws an error (Object reference not set to
an instance of an object). In order to populate the literal, this line
must work. That way, I can populate the "add" row's "ParentID" field
with the literal, so any additions will have the ParentID it requires.

Another problem is that I need to make this literal population fire only
when the database doesn't return any results. I have tried to find the
ASP.NET equivelents to the old rs.EOF rs.BOF methods, without success.
Any suggestions?

On another note, are there any tutorials that can show how I can have a
parent/child/grandchild/greatgrandchild datagrid (or close enough) with
every table being editable, deletable, and addable from within the same
datagrid? That is, you have "edit", "delete" and "add" buttons for every
layer of the datagrid.

TIA
....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********

Nov 19 '05 #2
Phillip Williams wrote:
Greetings Neo,

1- You should write a condition for if
ddlSelectRegion .SelectedItem.V alue.Equals ("") then write a different sql
statement
What I need to know is whether a returned dataset from the database is
empty or not. Would this work?:

If dgCarClubInfo.D ataSource = "" Then 'no data is returned, so...
Dim ltrRegionID as New Literal 'set the literal
ltrRegionID.Tex t = ddlSelectRegion .SelectedValue 'and populate it
Else
dgCarClubInfo.D ataBind() 'otherwise if data is returned, dont set
the literal, and just populate the datagrid.
End If
2- The reason you get “Object reference not set to an instance of an object”
is that you have not used the "New" keyword in instantiating the Literal
control
Dim ltrRegionID As New Literal
Strangely enough, this works. Don't know why (since six lines above it
is another DIM that wouldn't work like that...).
3- A simple way to create your expandable datagrid, is to use the
ItemDataBound event of the datagrid. This event would provide you a handle
to the datagrid item which is the analogy of a table row that contains cells.
You then loop through the cells collection of the DataGridItem, save their
values in a temporary array then rewrite an HTMtable that contains a child
datagrid bound to a child dataset. Something that uses the following code
components:

Public Class testGrid
Inherits System.Web.UI.W ebControls.Data Grid

Private Sub testGrid_ItemDa taBound(ByVal sender As Object, ByVal e As
DataGridItemEve ntArgs) Handles MyBase.ItemData Bound
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
BuildChildLayou t(e.Item)
End If

End Sub
Private Sub BuildChildLayou t(ByVal item As DataGridItem)
Dim row As DataGridItem = item
'loop through the row.Cells collection, and save their content in an
array
'remove all row.Cells
Dim newCell As New TableCell
row.Cells.Add(n ewCell)
Dim t As New Table
newCell.Control s.Add(t)
'now you have a Table (t) where you can re-write the values that you
saved above
'then add a new row, create a datagrid in it and bind it to the
child data
End Sub


End Class

Yes, but are the child/grandchild/greatgrandchild tables insertable,
updateable and deletable? that is what I am after. I want editing
controls on not only the parent, but on all three of its lower
generations. I simply don't know how to do that.

...Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #3
1- If you want to check if the returned dataset is empty before you bind it
to a grid, I would use a DataSet instead of a DataReader:
Dim da As New OleDb.OleDbData Adapter(myComma nd)
Dim ds As New DataSet
da.Fill(ds, "RegionID")
If ds.Tables("Regi onID").Rows.Cou nt >0 Then
'do something
Else
'do something else
End If

2- The Dim statement for scalar types (e.g. String) do not need the New
keyword
3- The answer to your question is Yes. Every datagrid (child, grand-child)
is simply another class that handles all of the events that you program in
it.

--
WEBSWAPP Development Inc.
http://www.webswapp.com
"Neo Geshel" wrote:
Phillip Williams wrote:
Greetings Neo,

1- You should write a condition for if
ddlSelectRegion .SelectedItem.V alue.Equals ("") then write a different sql
statement


What I need to know is whether a returned dataset from the database is
empty or not. Would this work?:

If dgCarClubInfo.D ataSource = "" Then 'no data is returned, so...
Dim ltrRegionID as New Literal 'set the literal
ltrRegionID.Tex t = ddlSelectRegion .SelectedValue 'and populate it
Else
dgCarClubInfo.D ataBind() 'otherwise if data is returned, dont set
the literal, and just populate the datagrid.
End If
2- The reason you get “Object reference not set to an instance of an object”
is that you have not used the "New" keyword in instantiating the Literal
control
Dim ltrRegionID As New Literal


Strangely enough, this works. Don't know why (since six lines above it
is another DIM that wouldn't work like that...).
3- A simple way to create your expandable datagrid, is to use the
ItemDataBound event of the datagrid. This event would provide you a handle
to the datagrid item which is the analogy of a table row that contains cells.
You then loop through the cells collection of the DataGridItem, save their
values in a temporary array then rewrite an HTMtable that contains a child
datagrid bound to a child dataset. Something that uses the following code
components:

Public Class testGrid
Inherits System.Web.UI.W ebControls.Data Grid

Private Sub testGrid_ItemDa taBound(ByVal sender As Object, ByVal e As
DataGridItemEve ntArgs) Handles MyBase.ItemData Bound
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
BuildChildLayou t(e.Item)
End If

End Sub
Private Sub BuildChildLayou t(ByVal item As DataGridItem)
Dim row As DataGridItem = item
'loop through the row.Cells collection, and save their content in an
array
'remove all row.Cells
Dim newCell As New TableCell
row.Cells.Add(n ewCell)
Dim t As New Table
newCell.Control s.Add(t)
'now you have a Table (t) where you can re-write the values that you
saved above
'then add a new row, create a datagrid in it and bind it to the
child data
End Sub
End Class

Yes, but are the child/grandchild/greatgrandchild tables insertable,
updateable and deletable? that is what I am after. I want editing
controls on not only the parent, but on all three of its lower
generations. I simply don't know how to do that.

...Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********

Nov 19 '05 #4
Phillip Williams wrote:
1- If you want to check if the returned dataset is empty before you bind it
to a grid, I would use a DataSet instead of a DataReader:
Dim da As New OleDb.OleDbData Adapter(myComma nd)
Dim ds As New DataSet
da.Fill(ds, "RegionID")
If ds.Tables("Regi onID").Rows.Cou nt >0 Then
'do something
Else
'do something else
End If

2- The Dim statement for scalar types (e.g. String) do not need the New
keyword
3- The answer to your question is Yes. Every datagrid (child, grand-child)
is simply another class that handles all of the events that you program in
it.

I've also ran into a very strange issue. When I try this code:

Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue. ToString()
ltrRegionID.Tex t = iRegionID

I get the following error message:

Name 'ltrRegionID' is not declared

Problem is, it is meant to be the ID of a asp:literal tag further down
on the page.

....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #5
Neo Geshel wrote:
I've also ran into a very strange issue. When I try this code:

Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue. ToString()
ltrRegionID.Tex t = iRegionID

I get the following error message:

Name 'ltrRegionID' is not declared

Problem is, it is meant to be the ID of a asp:literal tag further down
on the page.

...Geshel


But when I actually dim it:

Dim ltrRegionID as literal
ltrRegionID.Tex t = iRegionID

I get the following problem:

Object reference not set to an instance of an object.
Damned if I do, damned if I don't!!!!!

....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #6
Neo Geshel wrote:
Neo Geshel wrote:
I've also ran into a very strange issue. When I try this code:

Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue. ToString()
ltrRegionID.Tex t = iRegionID

I get the following error message:

Name 'ltrRegionID' is not declared

Problem is, it is meant to be the ID of a asp:literal tag further down
on the page.

...Geshel

But when I actually dim it:

Dim ltrRegionID as literal
ltrRegionID.Tex t = iRegionID

I get the following problem:

Object reference not set to an instance of an object.
Damned if I do, damned if I don't!!!!!

...Geshel

A bit of dicking around, and I've found the problem. Seems that a
dataset doesn't like a literal dropped in the middle of it. The literal,
in order to work, must exist outside the dataset.

So the question now is: how do I populate a table cell of the "add
record" footer of the dataset with a value pulled from the drop-down
list on the previous page? I need this, so that any record addition to
this child table will know which parent record to associate the new
record with.

Below is the code that I have come up with so far:

Sub ddlSelectRegion _Click(sender As Object, e As EventArgs)
Dim iRegionID as String
iRegionID = ddlSelectRegion .SelectedValue. ToString()
Dim myConn as New
OleDbConnection (ConfigurationS ettings.AppSett ings("strConn") )
myConn.Open()
Dim myCmd as New OleDbCommand("S ELECT Count(*) FROM tblCarClubInfo
WHERE [CarClubRegionID] = " & iRegionID, myConn)
If MyCmd.ExecuteSc alar() <> 0 Then
myCmd = New OleDbCommand("S ELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
dgCarClubInfo.D ataSource =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
dgCarClubInfo.D ataBind()
Else
myCmd = New OleDbCommand("S ELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
dgCarClubInfo.D ataSource =
myCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection)
dgCarClubInfo.D ataBind()
ltrRegionID.Tex t = iRegionID
End If
myConn.Close()
End Sub

Yes, the ELSE has a database call that I know will not return any
records, but I had to do this in order for the datagrid to actually be
built (otherwise it would not even appear, even as a single "add record"
line).

Now, what I would like to do, is have the RegionID cell of the "add
record" row in the DataGrid be populated by the above ELSE via another
route other than the DataSource (unless I can actually EDIT or ADD TO
the datasource dynamically after it's been called from the database!!!
That would be cool!) That way, the Region ID (which is not pulled from
the database, because there are no records returned) is still available
for the "add record" field for RegionID.

I have tried by using asp:literal, but this throws a bunch of errors, as
seen above, because it can't be inside of a datagrid. I have still
attached a value to a literal ID above (fourth line from bottom), but
I'm looking for another method.

Any help would be greatly appreciated.
....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #7
Neo Geshel wrote:
A bit of dicking around, and I've found the problem. Seems that a
dataset doesn't like a literal dropped in the middle of it. The literal,
in order to work, must exist outside the dataset.

So the question now is: how do I populate a table cell of the "add
record" footer of the dataset with a value pulled from the drop-down
list on the previous page? I need this, so that any record addition to
this child table will know which parent record to associate the new
record with.

Whoops. I meant "datagrid", not "dataset". Sorry.

....Geshel
--
*************** *************** *************** *************** **********
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
*************** *************** *************** *************** **********
Nov 19 '05 #8

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

Similar topics

4
62541
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work) I tried //title (doesn't work) I tried //title (doesn't work) Any suggestions welcome.
6
6069
by: Pavils Jurjans | last post by:
Hello, Here's the sample XML: <sample1></sample1> <sample2/> From many XML books and online documentations, it is said to be just different syntax for the same data. However, when we analyze the node
1
3659
by: Mark Barinstein | last post by:
Hello. W2k, db2 wse v8.1.4. Here is ddl that creates small test database (3 tables and 1 view). (i can't attach zip file with ixf files and loading script - it has ~ 1.3MB size, but if anybody want to get it i can download it on your site, mail me to __mark(at)mail.ru). --- CREATE DATABASE TEST ON C:;
5
1948
by: pcPirate | last post by:
Okay, I've have a mdiparentform and only one mdichild form. My parent form has a toolbar with only one button "Open Record". When a user click on the button, a child form would be shown. My child form retrieve a set of value from the MSSQL2K database and displays them in textboxes. And the users are able to change the value and save them (by clicking a save button) back to the database.
5
3548
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
3
12486
by: Fede | last post by:
Hi everybody, in vb.net I have this code: ...... myNode= XmlDoc.CreateElement("aNode") myAttribute = XmlDoc.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink") myAttribute.Value ="foo"
5
2346
by: paul.hester | last post by:
Hi all, I have a custom control with an overridden Render method. Inside this method I'm rendering each control in its collection using their RenderControl method. However, I'm running into a problem in this scenario: <myprefix:mycontrol runat="server"> <%= SomeVariable %> </myprefix:mycontrol>
8
3912
by: thatcollegeguy | last post by:
http://smarterfootball.com/exits/theHTML.html I am not sure what is wrong w/ this code. The main issue is that the table that is in the initial html will empty its td but the table that I load using php and jquery through a mysql database will not empty the td elements. There is a table underneath the button in the initial html. if you click on a box in the table, it will empty. the same does not happen for the table that is generated by...
0
9683
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10276
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9412
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7007
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5674
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5852
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.