Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can i insert blank value or null value in database..
its suitable to all datatypes like int, char ,and ,date, decimal ..


if i give null mean it not accept by integer
i give textbox.text="" it also not accepted wat the solution
Posted

use
int? i = null; 

or
Nullable<int> i = null;</int>

variable declaration.
 
Share this answer
 
Comments
suryaswathi 6-Jul-11 2:47am    
its give eroor null is non nullable value
[no name] 6-Jul-11 2:50am    
please provide the line of code....
suryaswathi 6-Jul-11 3:04am    
hello sir

colname data type Null

name varchar NotNull
id int Null
dob datetime notm null


my table mixed up with null and not null..but i want to insert null or blank value to all records in the fields..this is my query
[no name] 6-Jul-11 3:14am    
In database if the column is Allow NULL then only you can insert NULL value into it. And for string datatype like varchar, text, we can set black string. but in integer we cannot insert blank value. if it is allow null then insert NULL value else insert 0.

Try this

Insert into table values ('name', NULL, '12/FEB/2011');
NAME ID DOB
I'm not clear on what you are asking.

to insert a null value

insert into table
(column1, column2, column3)
values
(23, null,'Hello world')

Your textbox.text = implies you are using some programming language which has retrieved the data and are trying to display it, but have an issue if the data returned is null.

without knowing what programming language, any help needs to be generic - but you need to do something like


If row("column2") is DbNull.Value Then
  TextBox1.Text = String.empty
Else
  TextBox1.Text - row("Column2")
End If
 
Share this answer
 
Comments
suryaswathi 6-Jul-11 3:10am    
hello sir

colname data type Null

name varchar NotNull
id int Null
dob datetime notm null


my table mixed up with null and not null..but i want to insert null or blank value to all records in the fields..this is my query
_Maxxx_ 6-Jul-11 7:56am    
If you can't change the columns to acccept Null and you want to have a value that represents a null value, you have little choice but to use a 'magic' value for each field type that represents a Null value, then check for that in your code - so for int columns use -1, for exampel, for strings use an empty string (or "NULL") for dates use the minimum date value - more work in translating the magic values in your code - but nothing else you can do if you can't change the column properties

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900