473,382 Members | 1,336 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,382 software developers and data experts.

How do you set a value to Null in a DataSet when it's normally setto another table through a relation

I currently have a relation set up between two tables in my dataset.
Sometimes I'd like to set the value in the Foreign Key Field to NULL (if
it doesn't refrence the other table at all).

Currently i'm getting an error no matter what I try to use:
0
Nothing
Convert.DBNull

Does anyone have experience in this area? I posted this question a few
days ago, but I didn't have as clear of an understanding as I do right
now. Currently I can set this field to Null using the data grid,
however I havn't been able to figure out how to add a row with this
field set to Null - it always gives an error :(

~Benny
Nov 21 '05 #1
5 1202
If it doesn't reference the other table at all it's an Orphan which is what
the key there to prevent. You can try disabling the constraints but I
think that'd be a bad choice.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:aJ*******************@twister.nyroc.rr.com...
I currently have a relation set up between two tables in my dataset.
Sometimes I'd like to set the value in the Foreign Key Field to NULL (if
it doesn't refrence the other table at all).

Currently i'm getting an error no matter what I try to use:
0
Nothing
Convert.DBNull

Does anyone have experience in this area? I posted this question a few
days ago, but I didn't have as clear of an understanding as I do right
now. Currently I can set this field to Null using the data grid,
however I havn't been able to figure out how to add a row with this
field set to Null - it always gives an error :(

~Benny

Nov 21 '05 #2
use DBNull.Value Field

"Benny Raymond" wrote:
I currently have a relation set up between two tables in my dataset.
Sometimes I'd like to set the value in the Foreign Key Field to NULL (if
it doesn't refrence the other table at all).

Currently i'm getting an error no matter what I try to use:
0
Nothing
Convert.DBNull

Does anyone have experience in this area? I posted this question a few
days ago, but I didn't have as clear of an understanding as I do right
now. Currently I can set this field to Null using the data grid,
however I havn't been able to figure out how to add a row with this
field set to Null - it always gives an error :(

~Benny

Nov 21 '05 #3
That doesn't work, from that I get the error:
System.DBNull cannot be converted to WindowsApplication3.DataSet1.TreeRow

Rulin Hong wrote:
use DBNull.Value Field

"Benny Raymond" wrote:

Nov 21 '05 #4
Actually this morning I finally figured out how to do it. Instead of
using AddTreeRow("title",nothing,nothing) - which causes an error...
Instead I have to create a new row, set what I need to set, and then add
that row into the database like so:

Dim myrow As Dataset1.TreeRow = Dataset11.Tree.NewTreeRow
myrow.Title = "Title"
Dataset11.Tree.AddTreeRow(myrow)
Dataset11.Tree.Select()

It works perfectly and it's a lot easier to read than doing everything
in 1 large "AddTreeRow".

Hopefully someone else will find this useful as well.

~Benny
Nov 21 '05 #5
Actually this morning I finally figured out how to do it. Instead of
using AddTreeRow("title",nothing,nothing) - which causes an error...
Instead I have to create a new row, set what I need to set, and then add
that row into the database like so:

Dim myrow As Dataset1.TreeRow = Dataset11.Tree.NewTreeRow
myrow.Title = "Title"
Dataset11.Tree.AddTreeRow(myrow)
Dataset11.Tree.Select()

It works perfectly and it's a lot easier to read than doing everything
in 1 large "AddTreeRow".

Hopefully someone else will find this useful as well.

~Benny
Nov 21 '05 #6

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

Similar topics

3
by: Marcus | last post by:
I'm running into a situation that has me adding a value of "Unknown" to a reference table. I am being pulled between two trains of thought, and was curious to get other's input on in. I give an...
2
by: Devesh Aggarwal | last post by:
Hi, I have a backup and restore module in my project. The backup uses a typed dataset object (XSD) to get the data from database and creates a xml file as the backup file (using the WriteXml...
3
by: Fabio Negri Cicotti [MCP] | last post by:
Hi All. I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's SetParentRow method. The parent table has an identity column as primary key. When I execute the code below I...
0
by: Raed Sawalha | last post by:
I have DataSet with two tables constructed as following: 1. the DataSet is initially filled by DataAdapter . 2. a new DataTable is created and filled with data returned by a stored procedure 3....
4
by: Mat | last post by:
I have typed dataset and i don't know how to filter rows of table A according to children rows in table B Example TABLE USER has columns ID,Name Table USERNICK has columns nickname, ID ...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
4
by: Robert Bravery | last post by:
Hi all, I have now correctly set up my dataset and two grids, so that the parent navigates the child. THe thing is that the child table is actually a lookup type table. It lists billing types for...
2
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the #...
0
by: Dawnyy | last post by:
I have a typed dataset which I am populating using fill methods based on stored procedures. I have a form which contains a summary list of records and when a record is selected the detail of that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.