Hi Devaraneni,
You should check if the feature name existing in the database before inserting a new row.
If the feature name does not exist then only a new row should be inserted else an exception should be thrown and an error should be displayed in the UI.
I hope following code might help you.
Public Sub AddRecord(featureName As String)
Dim connection = New SqlConnection("Data Source=;Database=;User Id=;Password=")
Dim sqlCmd = New SqlCommand("select Top 1 FEATURE_NAME from MDT_MOBILE_FEATURES_SETTINGS WHERE FEATURES_NAME = @featureName")
sqlCmd.Parameters.Add(New SqlParameter("@featureName", featureName))
sqlCmd.CommandType = CommandType.Text
Dim result = sqlCmd.ExecuteScalar()
If result IsNot Nothing Then
Throw New Exception(String.Format("Feature name {0} already exist.", featureName))
End If
Dim sqlInsertCommand = New SqlCommand("INSERT MDT_MOBILE_FEATURES_SETTINGS(FEATURES_NAME) VALUES(@Name)")
sqlInsertCommand.Parameters.AddWithValue("@Name", featureName)
sqlInsertCommand.ExecuteNonQuery()
connection.Close()
End Sub
Thanks and regards,
Chetan Ranpariya