views:

27

answers:

1

hi friends i created a FTS by this article i have a column with type of varbinary(max) that i filled it with MSWord file(.doc) and another column with type of word(filled by .doc). when i run this script , the output is empty

SELECT 
    name,
    content
FROM tblWordFiles 
WHERE FREETEXT(content, '1');

or

SELECT 
    name,
    content
FROM tblWordFiles 
WHERE contains(content, '1');

where is my problem?

ooooooo! i used this code to fill database(c#)

    SqlConnection cn = new SqlConnection(@"Data Source=MJ;Initial Catalog=Test_word_binary;Integrated Security=True");
    string command = "insert into tblWordFiles (type,content) values('doc','@c')";
    SqlCommand cm = new SqlCommand(command, cn);
    DialogResult dg = openFileDialog1.ShowDialog();
    if (dg == DialogResult.OK)
    {
        // Create a new stream to load this photo into
        System.IO.FileStream stream = new System.IO.FileStream(openFileDialog1.FileNames[0], System.IO.FileMode.Open, System.IO.FileAccess.Read);
        // Create a buffer to hold the stream bytes
        byte[] buffer = new byte[stream.Length];
        // Read the bytes from this stream
        stream.Read(buffer, 0, (int)stream.Length);
        // Now we can close the stream
        stream.Close();

        cm.Parameters.Add("@c", SqlDbType.VarBinary).Value = buffer;
        cn.Open();
        cm.ExecuteNonQuery();
        cn.Close();
    }
+1  A: 

You're quoting the parameter @c, so its inserted as a literal value rather than the parameter's value.

See: insert into tblWordFiles (type,content) values('doc','@c')

Should be: insert into tblWordFiles (type,content) values('doc',@c)

I'm not sure whether the type column include the '.' or not ie, '.doc' or 'doc'

KeeperOfTheSoul
thanks keeperOfTheSoul
Meysam Javadi