Click here to Skip to main content
15,916,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI FRIENDS,

my project is based on asp.net c#, Sqlserver 2005.

I need help from you experts.

I have a table in SqlServer 2005 Database called TABLE(StudentDetails) with number of records in it.

and always I have one complete empty record in this table.


ON MY WEBPAGE I HAVE GRIDVIEW AND SUBMIT BUTTON

this submitbutton is to delete these records

so, when i delete the table complete table data is deleting..so i dont want to delete the empty record.

This empty record must be fixed in this table.

This is my code
------------------------
SqlConnection conDelete = new SqlConnection(_connString);
SqlCommand cmdDelete = new SqlCommand();
cmdDelete.Connection = conDelete;
cmdDelete.CommandText = "Delete from StudentDetails";
using (cmdDelete)
{
conDelete.Open();

cmdDelete.ExecuteNonQuery();
conDelete.Close();


}

and these are my fields in the StudentDetails Table
----------------------------------------------------
Student_code,Student_desc,Student_telno

please help

thanks
Posted
Comments
PrashantSonewane 16-Apr-13 2:32am    
can you help us understanding why you need empty record in table? I believe you are keeping this empty record to avoid null error. If so you can handle null issue properly and delete all records. However if you still want to have empty record then you should write condition in delete commandstring something like "Delete from StudentDetails where Student_code<>'' and Student_desc <> '' and Student_telno<>''

Hope this helps
PRAKASH9 16-Apr-13 2:32am    
what is the requirement for this type of condition?
vaibhav10Dec1987 16-Apr-13 2:36am    
Hi, Can you explain that line "always I have one complete empty record in this table."
or Is it mean there is an one empty row in "StudentDetails" table?
Why are you keep an empty records in that table?
Actually in programatic it is not a correct way to do these.It might be throws an exception.
Software Engineer 892 16-Apr-13 2:45am    
because i can see gridview footer textboxes, if we have atleast one record in gridview.

Otherwise i cannot see footer textboxes in gridview.

Please help
Software Engineer 892 16-Apr-13 2:45am    
I need one empty record fixed in table.
please help

Thanks

Dear,

An empty record could contains an empty value or null value as well.

Do retain empty records, you can use below sql query.

SQL
DELETE FROM StudentDetails 
WHERE ISNULL(Student_code,'') <> ''  
AND ISNULL(Student_desc,'') <> ''  
AND ISNULL(Student_telno,'') <> ''
 
Share this answer
 
Hi,

If you don't want to delete some records the n you must give some condition in that.

SQL
Delete from StudentDetails 
where Student_code<> '' and Student_desc <> '' and Student_telno<> ''


if you want more information regarding this check the below links

http://www.tutorialspoint.com/sql/sql-delete-query.htm[^]

http://www.w3schools.com/sql/sql_delete.asp[^]

I think this might be helpfull to you...
 
Share this answer
 
add emptydatatemplate in your gridview,hope it will help u for ur requirement
 
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