First of all, few notes:
1) If you want to use record set returnef by
SELECT
statement, you need to define relationship between
Contents
and
Sentences
tables.
SELECT c.ContentId, s.SentenceId
FROM Contents AS c INNER JOIN Sentences AS s ON c.PK = s.FK
where
c.PK
means Primary Key for
Contents
table and
s.FK
means Foreign Key form
Sentences
table. In other words, if there is no relationship between tables, the
cartesian result set[
^] is produced (CROOS JOIN).
For further information, please see:
Visual Representation of SQL Joins[
^]
2) The number of input and output fields must be equal!
INSERT INTO ContentSentences (ContentID,SentenceID,OrderNo)
SELECT ContentID, SentenceID, OrderNo
FROM ...
3) The data type must be the same!
If data type of
ContentId
and
SentenceID
is numeric, then the values returned by
SELECT
statement must be the same data type!
4) you can't build queries this way!
The proper way is to use command together with paramaters. Build the query this way:
SQL:
string qry = string.Concat("INSERT INTO ContentSentences (ContentID, SentenceID, OrderNo) ",
"SELECT ContentID, SentenceID, ", tb , " AS OrderNo ",
"FROM Contents ... Sentences ON ...",
"WHERE ContentText LIKE '@Param1' AND SentenceText LIKE '@Param2'");
OleDb:
string qry = string.Concat("INSERT INTO ContentSentences (ContentID, SentenceID, OrderNo) ",
"SELECT ContentID, SentenceID, ", tb , " AS OrderNo ",
"FROM Contents ... Sentences ON ...",
"WHERE ContentText LIKE '?' AND SentenceText LIKE '?'");
Because you did not provide enough information about your database provider, i can't show you sample code.
SqlCommand.Parameters Property[
^]
OleDbCommand.Parameters Property[
^]