如何检查每个员工的电话号码是不同的 [英] How to check phone number for each employee is different

查看:93
本文介绍了如何检查每个员工的电话号码是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请告诉我如何检查为每个员工输入的手机号码是否不同.如果数据库中已存在该手机号码,则当我使用tab或单击转到下一个文本框时,它应该会出错.

Hi
please tell me how to check that mobile number entered for each employee is different.if the number already exists in database it should give error when i go to next textbox using tab or click.

推荐答案

您可以使用以下几种方法进行操作:

1.使用电话号码作为按键,不允许重复.
2.在添加值之前,请执行一次选择调用并检查调用结果:
http://www.w3schools.com/sql/sql_select.asp [ http://www.fryan0911.com/2009/06/vbnet-how-to-select-records-from-sql.html [
You can do it using several methods:

1. Using the phone number as a key that don''t allow duplicates.
2. Prior to add the value execute a select call and check the result of the call:
http://www.w3schools.com/sql/sql_select.asp[^]
http://www.fryan0911.com/2009/06/vbnet-how-to-select-records-from-sql.html[^]

Showing the error depends on you but I would use a MessageBox or any other method to tell the user that something has gone wrong.

Hope this helps...


--for existing data
select * from table1 where MobileNo in -- fetch whole row having same numbers
(
     select mobileno from table1 group by  a having  count(*) > 1 -- fetch mobileno list which are repeated
)



输入数据时



When entering data

'on textbox leave event
       Dim exist = DBGetData("select count(*) from tabel1 where mobileno='" & txtmobileno.text & "'")
       If exist > 0 Then
           'show message not allowed
           'empty Mobile number textbox
           'focus txtmobileno
       End If


祝您编码愉快!
:)


Happy Coding!
:)


尝试一下
使存储的程序如下代码:
try this
Make Stored Procudureof below code:
create procedure check_contact_No
	@parameter_entered_contact_num as varchar(50)
as
begin
if(not Exists(select ad_contact_1 from admin_user_profile where ad_contact_1 = @parameter_entered_contact_num  ))
if( Exists(select ad_contact_1 from admin_user_profile where ad_contact_1 = @parameter_entered_contact_num  ))
	select COUNT(*) from admin_user_profile 
else 
	select COUNT(*) from admin_user_profile where ad_contact_1 = @parameter_entered_contact_num 
end


并在vb.net代码中检查此内容



and check this in vb.net code


'on textbox leave event
       Dim objcls As New database_Connection
        Dim da As New OleDbDataAdapter
        Dim ds As New DataSet
        Dim cmd As New OleDbCommand
        Dim con As New OleDbConnection
        Dim flag As Boolean
        Try
            con = objcls.GetConnection()
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "check_contact_No"
            cmd.Parameters.Add(New OleDbParameter("@parameter_entered_contact_num", txt_contactno.Text))
            cmd.Connection = con
            da.SelectCommand = cmd
            da.Fill(ds)
            If (ds.Tables(0).Rows.Count = 0) Then
                'show message not allowed
                'empty Mobile number textbox
                'focus txtmobileno
            Else
               'number is unique
               'do your coding
            End If
            Return flag
        Catch ex As Exception

        End Try


这篇关于如何检查每个员工的电话号码是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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