我通过article创建了一个FTS 我有一个varbinary(max)类型的列,我填充了MSWord文件(.doc)和另一个类型为word的列(由.doc填充)。 当我运行此脚本时,输出为空
SELECT
name,
content
FROM tblWordFiles
WHERE FREETEXT(content, '1');
或
SELECT
name,
content
FROM tblWordFiles
WHERE contains(content, '1');
我的问题在哪里?
OOOOOOO! 我用这段代码来填充数据库(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();
}
答案 0 :(得分:1)
您引用了参数@c,因此将其作为文字值而不是参数的值插入。
请参阅:insert into tblWordFiles (type,content) values('doc','@c')
应该是:insert into tblWordFiles (type,content) values('doc',@c)
我不确定类型列是否包含'。'或者不是'.doc'或'doc'