代码之家  ›  专栏  ›  技术社区  ›  Meysam Javadi

FTS使用故障

  •  0
  • Meysam Javadi  · 技术社区  · 17 年前

    我通过这个创建了一个FTS article 我有一个varbinary(max)类型的列,我用MSWord文件(.doc)填充了它,还有一个word类型的列(用.doc填充)。 运行此脚本时,输出为空

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

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

    噢噢噢! 我用这段代码填充数据库(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 回复  |  直到 16 年前
        1
  •  1
  •   Chris Chilvers    17 年前

    您引用的是参数@c,因此它是作为文字值而不是参数值插入的。

    请参阅: insert into tblWordFiles (type,content) values('doc','@c')

    应该是: insert into tblWordFiles (type,content) values('doc',@c)

    我不确定类型列是否包含“”。“或不是”,即“.doc”或“doc”

    推荐文章