Can't have zero-length string in a database field?

  • Thread starter Thread starter johnb41
  • Start date Start date
J

johnb41

I have a simple form that has a bunch of textboxes that show data from
a dataset table.

When I "Add" a record with BindingManagerBase.AddNew(), all the
textboxes go blank, so I can add a new record.

If I leave a field totally blank, and then click the Update button
(which uses the DataAdapter.Update() command, I get an error saying:

"Field 'Orders.Email' cannot be a zero-length string"

Does .NET not allow zero-length strings?

I tried programmatically adding a space (" ") to the textbox like this:

If tbEmail.Text = "" Then
tbEmail.Text = " "
'also tried tbEmail.text = chr(32)
'also tried tbEmail.text = vbnull
End If

But after I get the error, this textbox still has no space in it.

I'm stumped. Can someone help?

Thanks!
John
 
Hi John,

It's .net that's disallowing the add - it's your database. What is the
backend? What are the characteristics of the email column? Are you
updating using the commandbuilder or using manual update commands?

HTH,

Bernie Yaeger
 
its most likely the database:
for instance, the northwind database has some fields where 'allow null' is
true, but 'allow zero length' is false.
in other words, you can put null in the field - but not an empty string -
--- moral of the story - check the database , modify your code to set the
fields to null rather than an empty string
HTH
 
Back
Top