Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear Sir/Madam,


If i want to save record and that time i am not fill all records means leave some blank field and save this record.what code i can write in c#(Windows application) uing SQL 2005.
Posted
Comments
maan_k 3-Jul-13 1:51am    
have you allow that field as 'allow null' or not.if it is allow null then pass only that fields in insert query which you want to fill.i mean where is problem.tell ur requirement and code written by u.
Ashwini kumbhar 3-Jul-13 8:19am    
this field i used allow nulls but this field is not taking null value and also field is saved.so what i do

1 solution

It depends on the table schema. You can not leave fields blank that have no default or autogenerated value, but have a not null constraint.

SQL
CREATE TABLE #tmp(
  id INT NOT NULL identity(1,1),
  now DATETIME NOT NULL CONSTRAINT DF_MyTable_CreateDate_GETDATE DEFAULT GETDATE(),
  name varchar(100) not null,
  address varchar(100)
)

insert into #tmp(now, name, address) values('2013.01.01 10:25:00', 'John', 'Paris'); 
insert into #tmp(name, address) values('Peter', 'Berlin');
insert into #tmp(name) values('Bianca');
insert into #tmp(address) values('Bratislava'); -- will fail

select * from #tmp;

DROP TABLE #tmp


From here on, everything is normal ADO.NET: Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
 
Share this answer
 

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