Notify if a record already exists in the database before entering, filtering for three conditions. in visual basic and sql server

0

Dear good afternoon, I have the following dilemma, I can not do that in my system in visual basic with sql server database, at the moment of wanting to record a new datum in the table, if it exists, warn me of it, fulfilling three conditions at the same time (AND):

  • Do not have the same document number
  • Not belonging to the same area
  • What is not a document of the same year
  • I only find one condition, doing it in the following way, but when I put the 3 I do not find it:

    MiConexion.Open()
    SQL = "SELECT COUNT(*) FROM documentos WHERE numerodocumento = '" & TextBoxNumDoc.Text & "'"
    
    Com = New SqlCommand(SQL, MiConexion)
    Rs = Com.ExecuteReader()
    
    Rs.Read()
    LabelTomaNumeroDoc.Text = Rs(0)
    Rs.Close()
    MiConexion.Close()
    
    If LabelTomaNumeroDoc.Text = 0 Then
       Conectar.sqlconectar()
       Conectar.IngresarDoc()
    
        
    asked by Francisco 21.07.2017 в 21:45
    source

    1 answer

    0

    Friend you are doing a step less to extract the value, you lack something like this:

           If reader.HasRows Then
                Do While reader.Read()
                    LabelTomaNumeroDoc.Text = Rs(0)
                Loop
            Else
                LabelTomaNumeroDoc.Text = "0"
            End If
    

    Try what I add, the error is not reading the result well.

        
    answered by 21.07.2017 в 21:58