473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.name, the correct parenttable.ID is sent to
the next iteration of the page, where it is used as the
childtable.parentID 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.parentID 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(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
myConn.Open()
dgCarClubInfo.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
Dim ltrRegionID as Literal
ltrRegionID.Text = ddlSelectRegion.SelectedValue
dgCarClubInfo.DataBind()
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 1985
Greetings Neo,

1- You should write a condition for if
ddlSelectRegion.SelectedItem.Value.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.WebControls.DataGrid

Private Sub testGrid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles MyBase.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
BuildChildLayout(e.Item)
End If

End Sub
Private Sub BuildChildLayout(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(newCell)
Dim t As New Table
newCell.Controls.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.name, the correct parenttable.ID is sent to
the next iteration of the page, where it is used as the
childtable.parentID 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.parentID 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(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
myConn.Open()
dgCarClubInfo.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
Dim ltrRegionID as Literal
ltrRegionID.Text = ddlSelectRegion.SelectedValue
dgCarClubInfo.DataBind()
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.Value.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.DataSource = "" Then 'no data is returned, so...
Dim ltrRegionID as New Literal 'set the literal
ltrRegionID.Text = ddlSelectRegion.SelectedValue 'and populate it
Else
dgCarClubInfo.DataBind() '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.WebControls.DataGrid

Private Sub testGrid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles MyBase.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
BuildChildLayout(e.Item)
End If

End Sub
Private Sub BuildChildLayout(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(newCell)
Dim t As New Table
newCell.Controls.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.OleDbDataAdapter(myCommand)
Dim ds As New DataSet
da.Fill(ds, "RegionID")
If ds.Tables("RegionID").Rows.Count >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.Value.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.DataSource = "" Then 'no data is returned, so...
Dim ltrRegionID as New Literal 'set the literal
ltrRegionID.Text = ddlSelectRegion.SelectedValue 'and populate it
Else
dgCarClubInfo.DataBind() '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.WebControls.DataGrid

Private Sub testGrid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles MyBase.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
BuildChildLayout(e.Item)
End If

End Sub
Private Sub BuildChildLayout(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(newCell)
Dim t As New Table
newCell.Controls.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.OleDbDataAdapter(myCommand)
Dim ds As New DataSet
da.Fill(ds, "RegionID")
If ds.Tables("RegionID").Rows.Count >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.Text = 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.Text = 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.Text = 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.Text = 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.Text = 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(ConfigurationSettings.AppSettings( "strConn"))
myConn.Open()
Dim myCmd as New OleDbCommand("SELECT Count(*) FROM tblCarClubInfo
WHERE [CarClubRegionID] = " & iRegionID, myConn)
If MyCmd.ExecuteScalar() <> 0 Then
myCmd = New OleDbCommand("SELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
dgCarClubInfo.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
dgCarClubInfo.DataBind()
Else
myCmd = New OleDbCommand("SELECT * FROM tblCarClubInfo WHERE
[CarClubRegionID] = " & iRegionID & " ORDER BY [ID]", myConn)
dgCarClubInfo.DataSource =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
dgCarClubInfo.DataBind()
ltrRegionID.Text = 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
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)...
6
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...
1
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...
5
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...
5
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...
3
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") ...
5
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.