Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to insert null value in datetime field in sql/access database???

DataBase : Db_Xyz
Table: Tb_Abc
Col1(Varchar)
Col2(Int)
Col3(datetime)

Query:- insert into Tb_Abc(Col1,Col2,Col3)values('" + txtvalue1 + "','" + txtvalue2 + "','" + txtvalue3 + "'


Note:- Without using Parameter...

Help me...
Posted

1 solution

Try:
SQL
INSERT INTO Tb_Abc(Col1,Col2,Col3) VALUES ('" + txtvalue1 + "','" + txtvalue2 + "',NULL)

But please, don't do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
Comments
Manamohan Jha 20-May-14 12:08pm    
I am using this query in my windows application
how to set textbox in Null place???
OriginalGriff 20-May-14 12:18pm    
Use a parameterized query, and check the textbox content. If it's empty, then set the parameter value to DBNull.Value
PIEBALDconsult 20-May-14 12:23pm    
You could try a CASE to test for empty. But, really, use parameters.

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