Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi 1st create the record successful but 2nd time lo also show same msg box....
iam using bll and dal.
bll code:

how to check duplicate record:

VB
Public Shared Function CreateNewAMSRegMaintance(ByVal objAMSRegMaintance As clsAMSRegMaintance, ByVal tmprmno As Int32) As String
            If Not objAMSRegMaintance Is Nothing Then

                Dim TempId As String = dalAMSRegMaintance.CreateNewAMSRegMaintance(objAMSRegMaintance, tmprmno)
                If TempId = 0 Then
                    'objAMSRegMaintance.m_RMNO = tmprmno
                    'If Not TempId Is Nothing Then
                    objAMSRegMaintance.m_RMNO = tmprmno
                    Return True
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End Function


dal code:

VB
Public Shared Function CreateNewAMSRegMaintance(ByVal objAMSRegMaintance As clsAMSRegMaintance, ByVal tmprmno As Int32) As Integer

           If objAMSRegMaintance Is Nothing Then
               Throw New ArgumentNullException("objAMSRegMaintance")
           End If

           Dim db As DBAccess = New DBAccess
           Dim sqlCmd As SqlCommand = New SqlCommand()

           db.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, Nothing)
           db.AddParamToSQLCmd(sqlCmd, "@RMNO", SqlDbType.BigInt, 8, ParameterDirection.Input, tmprmno)
           db.AddParamToSQLCmd(sqlCmd, "@DEVICE_NO", SqlDbType.NVarChar, 6, ParameterDirection.Input, objAMSRegMaintance.DEVICE_NO)
           db.AddParamToSQLCmd(sqlCmd, "@SERIAL_NO", SqlDbType.NVarChar, 30, ParameterDirection.Input, objAMSRegMaintance.SERIAL_NO)
           db.AddParamToSQLCmd(sqlCmd, "@RHDATE", SqlDbType.NVarChar, 10, ParameterDirection.Input, objAMSRegMaintance.RHDATE)
           db.AddParamToSQLCmd(sqlCmd, "@RTIME", SqlDbType.NVarChar, 10, ParameterDirection.Input, objAMSRegMaintance.RTIME)
           db.AddParamToSQLCmd(sqlCmd, "@REMP", SqlDbType.NVarChar, 100, ParameterDirection.Input, objAMSRegMaintance.REMP)
           db.AddParamToSQLCmd(sqlCmd, "@REMPTELNO", SqlDbType.NVarChar, 15, ParameterDirection.Input, objAMSRegMaintance.REMPTELNO)
           db.AddParamToSQLCmd(sqlCmd, "@PROBLEMDESC", SqlDbType.NVarChar, 100, ParameterDirection.Input, objAMSRegMaintance.PROBLEMDESC)
           db.AddParamToSQLCmd(sqlCmd, "@RMFLG", SqlDbType.Int, 8, ParameterDirection.Input, objAMSRegMaintance.RMFLG)
           db.AddParamToSQLCmd(sqlCmd, "@ERROR", SqlDbType.VarChar, 100, ParameterDirection.Output, Nothing)
           db.SetCommandType(sqlCmd, CommandType.StoredProcedure, "SP_CREATEREGMAINTANCE")
           db.ExecuteScalarCmd(sqlCmd)
           Return CInt(sqlCmd.Parameters("@ReturnValue").Value)

       End Function


aspx.cs code:
VB
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
       Try
           Dim ret As Boolean

           Dim objAMSRegMaintance As clsAMSRegMaintance = New clsAMSRegMaintance
           Dim objAMSDALRegMaintance As dalAMSRegMaintance = New dalAMSRegMaintance
           If txtDevNum.Text <> "" Then
               objAMSRegMaintance.DEVICE_NO = Trim(txtDevNum.Text)
               objAMSRegMaintance.SERIAL_NO = Trim(txtSerialNum.Text)
               objAMSRegMaintance.RHDATE = Trim(txtRecHDate.Text)
               objAMSRegMaintance.RTIME = Trim(txtRecHTime.Text)
               objAMSRegMaintance.REMP = Trim(txtRecEmp.Text)
               objAMSRegMaintance.REMPTELNO = Trim(txtTelNum.Text)
               objAMSRegMaintance.PROBLEMDESC = Trim(txtPrbDesc.Text)
               objAMSRegMaintance.RMFLG = 0

               Dim tmprmno As Int32 = objAMSDALRegMaintance.GetAutoIncrementValue("TBL_MAINTENANCE", "RMNO")

               ret = clsAMSRegMaintance.CreateNewAMSRegMaintance(objAMSRegMaintance, tmprmno)
               If ret = True Then
                   Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('!تم الحفظ بنجاح');", True)
                   ClearTextBox(Me)
               Else
                   Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('في قسم الصيانة لعمل الصيانة اللازمة');", True)
                   ClearTextBox(Me)

               End If
           Else
               Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('!بجب تعبئة الحقول قبل الحفظ');", True)
           End If
       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
   End Sub
Posted

1 solution

Use this procedure
C#
CREATE PROCEDURE chkduplicate
(
   @name nvarchar(max)
)
AS
BEGIN
if exists (select * from  table where column_name= @name)
select 'True'
else
select 'False'
END

Read this value in your code and proceed further.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900