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

  • Thread starter Thread starter Benny Raymond
  • Start date Start date
B

Benny Raymond

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
 
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.
 
That doesn't work, from that I get the error:
System.DBNull cannot be converted to WindowsApplication3.DataSet1.TreeRow
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top