I'm trying to get relevant rows into datatable, i want only rows that have column value equal to one of the values in other sql table, that's my code:
try
{
sc.Open();
for (int i = 0; i < queryTokens.Length; i++)
{
cmd = new SqlCommand("INSERT INTO QueryIndex (Term) Values ('" + queryTokens[i] + "')", sc);
cmd.ExecuteNonQuery();
}
cmd = new SqlCommand("SELECT * FROM TermsIndex Where Term EXIST (Select Term From QueryIndex)");
SqlDataAdapter da = neuw SqlDataAdapter(cmd);
da.Fill(tempTable);
da.Dispose();
sc.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
the first part of the insert going well i'm sure, but in the second part, i hope you all understand what i'm trying to do, i know i have syntax errors here so please correct me, and i'm getting this exception message: {"Value cannot be null.\r\nParameter name: dataTable"} Null exception..
this is my sql create table:
CREATE TABLE [dbo].[TermsIndex]
(
[ID] VARCHAR(35) NOT NULL,
[Term] VARCHAR(35) NOT NULL,
[Frequency] int NOT NULL,
[Offset] VARCHAR(MAX) NOT NULL,
)
CREATE TABLE [dbo].[QueryIndex]
(
[Term] VARCHAR(MAX) NOT NULL,
)
so why i'm getting that null error? and anyway i'm creating a table just to be able to compare it's entries with column from the first one, i already had it string array, any chance to be able to compare that column value to changing number of strings (tokens) and return row results if it were equal to one of those strings in sql command? or any more elegance way to get the wanted result?