Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insertionof an existing term in a database

Status
Not open for further replies.

231166

Programmer
Apr 5, 2005
104
FR
Hi,

Here is my question,

I have created a table TERMES which contains two fields : ID_TERME(the identifier of each term) Lib_TERME(contains the label of each term).

I want to permit a user to type a same term in a treview at two different places in the treeview.

It means this term( the user can reuse) has one term above at one place of the treeview and has another term above at another place in the treeview.

The relation generic(terme which is above in the treeview)/specific(terme under the generic in the treeview)is in the Table GENERIQUES.
The field ID_TERME_SOURCE_G contains all the specific terms(child) and the field ID_TERME_GENERIQUE contains the generic terms(parent).

For example if we have

ID_TERME_SOURCE_G ID_TERME_GENERIQUE
2 8

it means that in the treeview we have this

8

2

8 and 2 are the tag of each term.

So now, if the user says he wants to reuse the term which tag is 2 and to put it under the term which tag is 10
he wants to see this in the treeview

8
2






10
2


Now i want to translate this in the code.

strLibelle is a new inputbox.
termexists is a boolean which indicates if the term already exists in the db.

Here is what is the present code i have written :
Code:
termexists = False
                For Each drTerme In objDS.Tables("TERMES").Rows
                    If strLibelle.ToLower = CType(drTerme.Item("Lib_TERME"), String) Then
                        termeexiste = True
                     

If MessageBox.Show("this term is already in the database, do you want to reuse it?", "addition of a new term", MessageBoxButtons.YesNoCancel) = DialogResult.Yes Then
                            strSQLInsertGeneriqueTermerepete = "INSERT into GENERIQUES (ID_TERME_SOURCE_G, ID_TERME_GENERIQUE) values ( " & CType(drTerme.Item("ID_TERME"), Integer) & " , " & strTag.Substring(2).ToString & ")"
                            objConn.Open()
                            objinsertgeneriquetermerepete = New SqlCommand(strSQLInsertGeneriqueTermerepete, objConn)
                            objinsertgeneriquetermerepete.ExecuteNonQuery()
                            objConn.Close()

But i receive an error at this level " & CType(drTerme.Item("ID_TERME"), Integer) & "

Could you explain to me why and help me to correct this sql request to obtain an exact one.

Thanks a lot for all your help.

Best regards.
Nathalie
 
What is the error you are getting?

I don't think you ned to do the cast to Integer with CType, since what you want is a string value to append into the SQL string. Try using just & drTerme.Item("ID_TERME") &, without the CType.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top