2009-09-02 145 views
0

我創建了一個FTS這article 我有一個類型的varbinary(最大),我填充了MSWord文件(.doc)和另一列字類型(填充.doc)的列, 。 當我運行此腳本,輸出是空FTS使用故障

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(); 
    } 

回答

1

你報價參數@c,所以其作爲一個文本值,而不是參數的值插入。

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

應該是:insert into tblWordFiles (type,content) values('doc',@c)

我不知道該類型的列是否包括 ''或不是,即'.doc'或'doc'

+0

謝謝keeperOfTheSoul – 2009-09-02 12:57:44