insert an empty string into a database

rockwell

Active member
Joined
Dec 6, 2005
Messages
36
Programming Experience
Beginner
hi all, i am using ms access as my database. I have many textboxes for user entry and some of those text boxes might me empty too.

So i just tested if i can insert a null value into a database if the textfield is empty with 4 textboxes.

For Each control As Control In Me.Controls
If control.Text = "" Then
control.Text = "NULL"
End If
Next

cmd = New OleDbCommand("Insert into hhh(CustomerID,name,Date,Org) values ('" & txtCustomerID.Text & "','" & txtCustomerName.Text & "','" & txtDate.Text & "','" & txtOrg.Text & "')", Myconn)
cmd.ExecuteNonQuery()

i got an error while inserting into database if i do this, i know the syntax might be wrong or something else ..

Any suggestions please as to how to do it ...

Thanks for your time ....
 
if you want to insert a null value in the database , you have to include nothing between the comm and remmber that allow null property in the tables is turned to true , please send the error that appears

Michael Louis Gabriel
Senior Programmer
MCSD , MCAD
Gaeasoft Group
http://www.gaeasoft.net
 
but some textboxes might me numbers as well and the database has a number field for it. The error i am getting when trying to insert an empty string for is

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Thanks for your time ...
 
Back
Top