Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

allow null value in textfield 1

Status
Not open for further replies.

Jaminj

Technical User
Feb 19, 2005
54
US
Hello. I am using the following code to insert values from textboxes to an sql database:

cmdInsert.Parameters.Add( "@cigbook", SqlDbType.Money ).Value = txtcigbook.Text

How do I modify this to allow null values? I get an error when I try to submit the form if all the fields are not filled out. I am using Visual Studio .NET. Thanks.
 
use the IsNull() function to check txtcigbook.text. If you want to pass Null as a Parameter, then the field in the SQL Table must also allow Nulls. This is specified in the Table Design.



Sweep
...if it works dont f*** with it
curse.gif
 
Jaminj, this has worked for me in the past:

Code:
If trim(txtcigbook.text) = "" then
  cmdInsert.Parameters.add("@cigbook", SqlDbType.Money).value = DBNull.Value
Else
  cmdInsert.Parameters.add("@cigbook", SqlDbType.Money).value = txtcigbook.text
End If

Hope that helps.
Rudy
 
Thanks guys. I used the solution that dolfo35 provided and it works perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top