Re: Insert null in database
The fact that you're calling ToString should have given it away. DBNull.Value is a null value, but calling ToString turns it into an empty String object, which is not the same thing. Plus, I'm guessing that your column takes numerical values, so you should NOT be assigning a String object to it at all. txtVervangcode.Text is a String, so that's wrong. You should be converting that to the appropriate type too.
Re: Insert null in database
I'm still getting problems, I tried the above this way:
VB Code:
row.article_id = IIf(txtArticle_id.Text.Equals(""), DBNull.Value, CType(txtArticle_id.Text, Integer))
This gives an error about DBNull cannot be converted to an Integer.
Some help would be greatly appreciated because I really need to get this fixed.
Thanks
Nik
Re: Insert null in database
I can't check it but on top off my head the ff. logic may work though it's not 100% since if you decide to update a field to null then it won'r work...
VB Code:
If Not txtArticle_id.Text.Equals("") THEN
row.article_id = CType(txtArticle_id.Text, Integer)
End If
Re: Insert null in database
Have you allowed nulls to be inserted in that column? Also, posting the exact error message is always a good idea. The precise details can be important.
Re: Insert null in database
Quote:
Originally Posted by jmcilhinney
Have you allowed nulls to be inserted in that column?
He/she specified it in his/her first post...
Quote:
Originally Posted by Nikske
I have a table with a decimal field that allowes null-values.
Re: Insert null in database
I'm a he for the record :)
I'm making progress:
VB Code:
If Not Trim(CType(txtNaam.Text, String)).Length = 0 Then 'verplicht
row.naam = CType(txtNaam.Text, String)
End If
So when I leave the textbox empty I 'm getting an "not null allowed in field naam". This is what I wanted.
But now I have another problem with unique value's. I have an unique index on a field in the sql table. From this table I make a typed dataset. Now I can add non-unique values into the dataset. But when I try to save it to the dB I get an error that non-unique values are found. Is there a way to add an unique index on a typed dataset, so I get this error when I add non-unique values into the dataset?
Re: Insert null in database
Quote:
Originally Posted by dee-u
He/she specified it in his/her first post...
I knew that. :blush: