如何在创建新用户期间防止使用相同的用户ID? [英] How to prevent same user-id during a new user creation?

查看:84
本文介绍了如何在创建新用户期间防止使用相同的用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中创建新用户期间防止插入相同的用户ID?如何从sqlserver中进行检查?

How to prevent same user-id insertion during a new user creation in asp.net?how will I do the checking from sqlserver?

推荐答案

获取ID表的列主键 [ SQL主键约束 [
Make the ID column of your table Primary Key[^]

SQL PRIMARY KEY Constraint[^]
-The PRIMARY KEY constraint uniquely identifies each record in a database table.
-Primary keys must contain unique values.
-A primary key column cannot contain NULL values.
-Each table should have a primary key, and each table can have only ONE primary key.


您需要通过以下查询来检查它:
You need to check it via a query like:
SELECT COUNT(*) FROM MyTable WHERE UserName  = @CheckUserName


如果从数据库返回的计数大于零,则意味着用户名已被使用.

使用查询调用DB,并根据检索到的结果实现流程.尝试!


If the count returned from the database is greater than zero then it means that the username is already taken.

Call DB using the query and implement the flow based on the result retrieved. Try!


有几种方法可以做到这一点.

-对表的名称"列使用唯一约束.这样可以防止插入重复的用户ID.

-提交时,您可以检查此用户ID在数据库表中是否已经存在.

-您可以提供一个按钮,以在提交之前检查用户ID的唯一性.
There is several way you can do this.

- use unique constraints with column Name of your table. it prevents to insert duplicate user-id.

- On submit, you can check whether this user-id is already exist or not in your db table.

- you can provide a button to check uniqueness about user id before submit.


这篇关于如何在创建新用户期间防止使用相同的用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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