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

问题描述


请告诉我如何检查为每个员工输入的手机号码是否不同.如果数据库中已存在该手机号码,则当我使用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.

推荐答案


--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!
:)


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


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

10-27 19:51