如何避免将重复值绑定到textbox字段的下拉列表中? [英] how to avoid the binding of duplicate values in to dropdownlist from textbox field?

查看:49
本文介绍了如何避免将重复值绑定到textbox字段的下拉列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们...我的页面中有4个文件,数据库名称是4列的技能。他们是skillid,skillname(textbox1),parentskill(下拉列表),最后是filtertext(textbox2)。

注意:首先我们的数据库表是空的

这里在设计table时,skillid被保存为autogenerate id号。对于用户来说,技能ID是不可见的......

so..user将在textbox1中输入.NET等详细信息,因为我们知道.NET是parentkill rt所以用户不会选择下拉列表中的任何项目,他只在.NET中输入过滤文本中的值。

现在在技能表中插入的第一行就像这样的1 .NET NULL .NET,现在页面回发之后,.NET必须输入到dropdownlist ...
现在用户将输入这样的详细信息..2 c#1 csharp其中1表示

父.NET(技能编号)....像这样插入行..



skillid skillname parentskill filtert ext

1 .NET NULL .NET

2 C#1 CSHARP

3 ASP.NET 1 .NET

4 J2EE NULL J2EE

5 JAVA 4 JAVA



如上所述我完成了任务,但我无法避免输入重复值到我的下拉列表... plz帮我查询frnds

hi friends...i have a 4 fileds in my my page and database name is skills having 4 columns.they are skillid,skillname(textbox1),parentskill(dropdownlist) and finally filtertext(textbox2).
note:At first our database table is empty
here skillid is kept as autogenerate id number while designing the table.so skillid is not visible to user...
so..user will enter the details like ".NET" in textbox1 and as we know that .NET is the parentskill rt so user wont select any item in dropdownlist and he entered the value in filter text like ".NET" only.
Now in skills table the first row is inserted like this "1 .NET NULL .NET",Now after the page is postback .NET shoulbe be enter in to dropdownlist where...
now user will enter the details like this.."2 c# 1 csharp" where here "1" represents the
parent .NET (skillid number).... like this the rows are inserted..

skillid skillname parentskill filtertext
1 .NET NULL .NET
2 C# 1 CSHARP
3 ASP.NET 1 .NET
4 J2EE NULL J2EE
5 JAVA 4 JAVA

as above i completed the task but im anot able to avoid the entry of duplicate values in to my dropdownlist...plz help me the query frnds

推荐答案

最简单的方法是在存储过程或查询中进行重复检查以插入记录。



例如:

The easiest way would be to do the duplicacy check in the stored procedure or query for inserting the record.

For example:
IF(NOT EXISTS(SELECT 1 FROM Skills WHERE skillname=@SkillName AND parentskill=@ParentSkill))
BEGIN
   //insert logic
END
ELSE
BEGIN
   //show duplicate exist msg
   SELECT 'Duplicate exists'
END



现在你可以检查查询/存储过程是否返回任何内容然后它插入失败并需要显示重复消息,如果成功,则表示它不会返回任何内容。



希望,它有帮助:)


Now you can check if the query/stored proc returns anything then it has failed inserting and need to show the duplicacy message and if it succeeds, it means it will return nothing.

Hope, it helps :)


使用主键来避免这种情况,并使用下拉列表绑定下拉列表..
use a primary key to avoid this and bind the dropdown with dropdown Id..


这篇关于如何避免将重复值绑定到textbox字段的下拉列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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