C# .NET 中实现类似于化学表达式的,平方等的上下标的实现方法

C# .NET 中实现类似于化学表达式的,平方等的上下标的实现方法

一。将特殊格式的文字内容插入到Sql Server 2000数据库中。
string strconn = "server=StarK;database=Super_Sub_Test;uid=sa;pwd=sa";
          SqlConnection   conn   =   new   SqlConnection(strconn);  
          conn.Open();  
          //执行存储语句  
          string sqlStr = "insert   into   rtf(rtfRead)  values(@rtfRead)";
          SqlCommand   myCommand   ;  
          try  
          {  
              myCommand   =   new   SqlCommand(sqlStr,   conn);
              myCommand.Parameters.Add(new SqlParameter("@rtfRead", SqlDbType.Image));  
          }  
          catch  
          {  
             return   ;  
          }  
          try  
          {  
              byte[]   biStr   =   new   byte[Convert.ToInt32(richTextBox1.Text.ToString().Length   )];///????  
              biStr=System.Text.Encoding.Unicode.GetBytes(richTextBox1.Rtf);
              myCommand.Parameters["@rtfRead"].Value = biStr;  
          }  
          catch  
          {  
            return   ;  
          }  
          try  
          {  
            myCommand.ExecuteNonQuery();  
            
          }  
          catch        
          {  
            return   ;  
          }  
          conn.Close();



二,将特殊字符从数据库中读取出来
richTextBox2.Text = "";            
            string strconn = "server=StarK;database=Super_Sub_Test;uid=sa;pwd=sa";
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            byte[] DocBody = null;
            string selStr = "select rtfRead from rtf where ID=6";
            SqlCommand myCommand = new SqlCommand(selStr, conn);
            System.Data.SqlClient.SqlDataReader myReader;
            myReader = myCommand.ExecuteReader();
            if (myReader.Read())
            {
                System.Data.SqlTypes.SqlBinary sqlB;
                sqlB = myReader.GetSqlBinary(0);
                if (sqlB.Value.Length > 0)
                {
                    DocBody = new Byte[sqlB.Value.Length];
                    sqlB.Value.CopyTo(DocBody, 0);
                }
                //richTextBox2.Text = System.Text.UnicodeEncoding.Unicode.GetBytes(DocBody);
                //biStr=System.Text.EncodingUnicode.GetBytes(richTextBox1.Rtf);
                this.richTextBox2.Rtf = System.Text.UnicodeEncoding.Unicode.GetString(DocBody);
                
            }
            myReader.Close();
            conn.Close();  


代码讲述的实现,而没有讲求代码实现的效率。可以在这个基础上优化代码

转载于:https://www.cnblogs.com/evonchang/archive/2008/04/20/1163004.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值