1.编写一个存储10个用户名的程序.当用户重新输入其名称时,程序应显示消息"Already Exists". [英] 1. Write a program that stores 10 user names. When the user re-enters his name the program should display the message “Already Exists”.

查看:67
本文介绍了1.编写一个存储10个用户名的程序.当用户重新输入其名称时,程序应显示消息"Already Exists".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 编写一个存储10个用户名的程序.当用户重新输入名称时,程序将显示消息已经存在".

解决方案

使用存储过程(如果使用数据库):

 创建 过程 spempcheck
(
     @ empid   varchar ( 50 ),
     @状态 字符( 1 )输出
)
开始
    声明  @ cnt   int 
    声明  @ errmsg   varchar ( 1000 )
    
    选择 @ cnt = count(*)来自 Emp 其中 Emp_id = @ Empcode
    如果(@ cnt> 0)
       开始
           set  @ status = '  T'
       结束
    其他
       开始
           set  @ status = '  F'
       结束
结束 



然后在代码中检查存储过程是否返回T或F.如果T则显示消息记录已存在"


使用字典存储用户名和密码

用户名是字典的关键字,重复出现会抛出异常


hi Write a program that stores 10 user names. When the user re-enters his name the program should display the message "Already Exists".

解决方案

Use stored procedure (if you are using database):

CREATE PROCEDURE spempcheck
(
    @empid varchar(50),
    @status char(1) output 
)
Begin
    declare @cnt int
    declare @errmsg varchar(1000)
    
    select @cnt=count(*) from Emp where Emp_id=@Empcode
    if(@cnt>0)
       begin
          set @status='T'
       end
    else
       begin
          set @status='F'
       end
End



Then inside your code check whether the Stored Procedure is returning T or F. If T then show message "Record already exists"


using Dictionary to store the username and password

username is the key of the Dictionary and .Duplication occur it will throw the Exception


这篇关于1.编写一个存储10个用户名的程序.当用户重新输入其名称时,程序应显示消息"Already Exists".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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