i create one function but in return function so there is error like argument not specified for parameter 'arguments' of public function give some proper soluation and code for checking same value in database and if value are same then msg box show value are exists and new value then insert data

 Public Function UserExit(ByVal empcode As Boolean) As Boolean
        Dim cmd As New SqlCommand("select * from EmMaster where  EmploHba_EmpCode =@ec  ")

        cmd.Parameters.AddWithValue("@ec", txtEmpCode.Text.Trim())

        cmd.CommandType = CommandType.Text
        cmd.Connection = cn
        cn.Open()
        Dim dr As New SqlDataReader
        dr = cmd.ExecuteReader()
        If (dr.HasRows) Then
            Return True
        Else
            Return False
            cn.Close()

        End If
    End Function

      Private Sub txtEmpCode_LostFocus(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles txtEmpCode.LostFocus
        UserExit()
        UserExit.this.userexit()



        If(UserExit == False) then

        Else
            MessageBox.Show("EXIXTS DATA")
        End If

Edited 9 Months Ago by Parth_3

Your signatures for the userExit method don't match. You're calling it with no parameters but the method signature expects a variable called empCode.

hericles is correct.
Firstly you called the function without parameter value.
Secondly codes in function UserExit() need some change. No need to use datareader. Just you have to sure any value exist or not in the table.
I just change in your codes, you can use it if you want. Hope it can help you.

Public Function UserExit(empcode As String) As Boolean
    Dim conn As New MySql.Data.MySqlClient.MySqlConnection
    conn.ConnectionString = appConnectionString
    If conn.State = System.Data.ConnectionState.Closed Then conn.Open()
    Dim cmd As New MySql.Data.MySqlClient.MySqlCommand
    cmd.CommandType = CommandType.Text
    cmd.CommandText = "Select Count(*) From EmMaster Where EmploHba_EmpCode =@empcd"
    cmd.Parameters.AddWithValue("@empcd", empcode)
    cmd.Connection = conn
    Dim Result As Integer = cmd.ExecuteScalar()
    cmd.Parameters.Clear()
    cmd.Dispose()
    conn.Close()
    conn.Dispose()
    If Result > 0 Then
        Return True
    Else
        Return False
    End If
End Function

Private Sub txtEmpCode_LostFocus(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles txtEmpCode.LostFocus
    If UserExit(CType(e.OriginalSource, TextBox).Text) Then
        MessageBox.Show("User Exists. Please input a unique value.")
        CType(e.OriginalSource, TextBox).SelectionStart = 0
        CType(e.OriginalSource, TextBox).SelectionLength = CType(e.OriginalSource, TextBox).Text.Length
    End If
End Sub

Edited 9 Months Ago by Reverend Jim: Corrected code formatting

Comments
ty for help me but
   If UserExit(CType(e.OriginalSource, TextBox).Text) Then

but one error show me this line like Unable to cast object of type 'System.Windows.Controls.Button' to type 'System.Windows.Controls.TextBox'.

Thanks Jim for editing my post. I posted that from smartphone. Thraer are no formating option exist.
Thanks Jim.

This article has been dead for over six months. Start a new discussion instead.