''' <summary> ''' This a generic function to find duplicate records in tables where the Primary Key is an integer ''' </summary> ''' <returns>True if duplicate records are found.</returns> ''' <remarks>This code will only work for Integer PK, if using other type, simply change the CType in the return statement.</remarks> Public Function DuplicateRecordFound() As Boolean '-- Create the SqlCommand with an Using to automatically dispose it. Using cmd As New SqlCommand cmd.CommandType = CommandType.Text cmd.CommandText = String.Format("SELECT COUNT({0}) FROM {1} WHERE {0} > 0 GROUP BY {0} HAVING COUNT(1) > 0", Me.PrimaryKeyField, Me.TableNameAndSchema) '-- Execute the query and return the value Return CType(Me.ExecuteScalar(cmd), Integer) > 0 End Using End Function
Using bo As New bizTransactionItems If bo.DuplicateRecordFound = True Then ' Do whatever you want here. End If End Using
MicroFour.StrataFrame.Data.DataBasics.DataSources("").ExecuteNonQuery(cmd)
Thanks for the help.
me.ExecuteNonQuery(cmd)
I get an error that says ExecuteNonQuery is not a member of Rodeo.CheckforDupsfrm
I know that it probably just in not the correct syntax because it is in the click of a button but I tried a couple of things and they did not work either.?
Dim nret As Integer = 1000 Dim cmd As New SqlCommand("sp_CountSRStockforDups") cmd.CommandType = Data.CommandType.StoredProcedure ' OutPut Parameter cmd.Parameters.Add("@myRowCount", Data.SqlDbType.Int).Direction = Data.ParameterDirection.Output nret = CType(cmd.Parameters("@myRowCount").Value, Integer)