当前位置:编程学习 > C#/ASP.NET >>

SQL全文检索 打开搜索到的文件让关键字显示红色怎么做

哪位大侠帮我看看为什么我替换关键字不管用,应该怎么修改呀谢谢
这是我的程序
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    string str;
   
   protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        string seletc = "select * from search1 where contains(MyImage, '" +TextBox1.Text + "')";
       
        SqlDataAdapter da = new SqlDataAdapter(seletc, myConn);
        DataSet ds = new DataSet();
        da.Fill(ds, "search");
        DataGrid1.DataSource = ds.Tables["search"].DefaultView;
        DataGrid1.DataBind();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
        }
        string sql = "select   *   from   search1   where   id   =  '" + Request.QueryString["id"] + "'";
        SqlConnection connection = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        SqlCommand command = new SqlCommand(sql, connection);
        connection.Open();
        SqlDataReader dr = command.ExecuteReader();
        if (dr.Read())
        {
            
            Response.Clear();
            Response.Charset = "GB2312";

            Response.ClearHeaders();
            Response.BufferOutput = true;
            Response.AddHeader("content-type", Request.QueryString["FileType"]);
            Response.ContentType = "application/msword";
            dr["MyImage"].ToString().Replace(TextBox1.Text, "<font color=red>" + TextBox1.Text + "</font>");
            
            Response.BinaryWrite((byte[])dr["MyImage"]);


        }
        dr.Close();
        connection.Close();
    }
}

我用replace替换了关键字但打开文件还是什么效果都没,哪位大侠看看是怎么回事谢谢,在线等 --------------------编程问答-------------------- 哪位大侠帮忙看看 100分求各位大侠解决一下问题谢谢 --------------------编程问答--------------------

//                        dr["MyImage"].ToString().Replace(TextBox1.Text,   " <font   color=red> "   +   TextBox1.Text   +   " </font> ");
//上面这行不要
//Response.BinaryWrite((byte[])dr["MyImage"]); 
//上面这行换为
Response.BinaryWrite((byte[])dr["MyImage"].Replace(TextBox1.Text,   " <font   color=red> "   +   TextBox1.Text   +   " </font> "); 
--------------------编程问答-------------------- 不好意思,忘不了tostring 了

Response.BinaryWrite((byte[])dr["MyImage"].ToString().Replace(TextBox1.Text,   " <font   color=red> "   +   TextBox1.Text   +   " </font> "); 
--------------------编程问答-------------------- 大哥还是提示错误呀
提示无法将byte[]类型转换为string类型能教我怎么解决吗 --------------------编程问答-------------------- 那么哪一列是要被高亮的,列名叫什么,你将对应的处理一下就行了. --------------------编程问答-------------------- MyImage列是要被高亮的myImage列是我数据库文件存储的列,我需要怎么处理呀? --------------------编程问答-------------------- jf
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,