单击删除按钮时,不得从表中删除空记录 [英] empty record must not be deleted from table when delete buton clicked

查看:50
本文介绍了单击删除按钮时,不得从表中删除空记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI FRIENDS,



我的项目基于asp.net c#,Sqlserver 2005.



我需要专家的帮助。



我在SqlServer 2005数据库中有一个名为TABLE(StudentDetails)的表,其中包含记录数。



我总是在这张桌子上有一张完整的空记录。





我的网页我有GRIDVIEW和提交按钮



此提交按钮是删除这些记录



所以,当我删除表完整表数据正在删除..所以我不想删除空记录。



这个空记录必须在此表中修复。



这是我的代码

------------------------

SqlConnection conDelete = new SqlConnection(_connString);

SqlCommand cmdDelete = new SqlCommand();

cmdDelete.Connection = conDelete;

cmdDelete.CommandText =从StudentDetails中删除;

使用(cmdDelete)

{

conDelete.Open();



cmdDelete.ExecuteNonQuery();

conDelete.Close();





}



这些是我在StudentDetails表中的字段

-------------- --------------------------------------

Student_code,Student_desc, Student_telno



请帮助



谢谢

解决方案

亲爱的,



空记录也可能包含空值或空值。



保留空记录,可以使用下面的sql查询。



  DELETE   FROM  StudentDetails 
WHERE ISNULL(Student_code, ')<> ' '
AND ISNULL (Student_desc,' ')<> ' '
AND ISNULL (Student_telno,' ')<> ' '






如果你不想删除某些记录,你必须给出一些条件。



 删除 来自 StudentDetails 
其中 Student_code<> ' ' Student_desc<> ' ' Student_telno<> ' '





如果您想了解有关此项检查的更多信息,请点击以下链接



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



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



我认为这可能对你有所帮助......


在gridview中添加emptydatatemplate,希望它能帮助你满足你的要求


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

解决方案

Dear,

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

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

DELETE FROM StudentDetails 
WHERE ISNULL(Student_code,'') <> ''  
AND ISNULL(Student_desc,'') <> ''  
AND ISNULL(Student_telno,'') <> ''


Hi,

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

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...


add emptydatatemplate in your gridview,hope it will help u for ur requirement


这篇关于单击删除按钮时,不得从表中删除空记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆