Hi,
I would like to permit a user to insert in a treeview a new term .This new term will be inserted in a table called 'TERMES'.
the problem is that the same term has not to be inserted twice in the database.
The user types the new term in a inputbox called 'strLibelle' and after, the program compares the text inserted in the input box to all the terms's label of the TERMES table( field Lib_TERME).
The TERMES table created with the dataset is called also TERMES
Here is the code
the problem is that the insertion in the database is done each time the comparison between the Lib_Terme in the table TERMES and the content of strLibelle gives a result = true(strLibelle<>"Lib_TERME"), that means that if i have 50 terms in the database, ithe insertion of the new term is done 50 times!!!
Could you help me to correct this to make the insertion only one time in the database.
Thanks a lot for all your help.
Best regards
Nathalie
I would like to permit a user to insert in a treeview a new term .This new term will be inserted in a table called 'TERMES'.
the problem is that the same term has not to be inserted twice in the database.
The user types the new term in a inputbox called 'strLibelle' and after, the program compares the text inserted in the input box to all the terms's label of the TERMES table( field Lib_TERME).
The TERMES table created with the dataset is called also TERMES
Here is the code
Code:
For Each drTerme As DataRow In objDS.Tables("TERMES").Rows
If strLibelle.ToLower <> drTerme.Item("Lib_TERME") Then
strSQLInsertTerme = "INSERT INTO TERMES(Lib_TERME,EM,ID_THES) VALUES ('" & strLibelle & "','0'," & intNumThes.ToString & ")"
objInsertTerme = New SqlCommand(strSQLInsertTerme, objConn)
objInsertTerme.ExecuteNonQuery()
Else
MessageBox.Show("this term already exists in the database", "Ajout d'un nouveau terme", MessageBoxButtons.OK)
End If
Next
the problem is that the insertion in the database is done each time the comparison between the Lib_Terme in the table TERMES and the content of strLibelle gives a result = true(strLibelle<>"Lib_TERME"), that means that if i have 50 terms in the database, ithe insertion of the new term is done 50 times!!!
Could you help me to correct this to make the insertion only one time in the database.
Thanks a lot for all your help.
Best regards
Nathalie