zoukankan      html  css  js  c++  java
  • c# winform学习记录(链接数据库,修改字体颜色)

    • sql server数据库配置(windows 身份认证)
      •   config文件添加如下代码
        •   
          <connectionStrings>
                <add name="conn"  connectionString="Server=**;Integrated Security=SSPI;" />
          </connectionStrings>
          
          代码添加
          • //开头添加
            using System.Configuration;
            using System.Data.SqlClient;
            
            //链接
            string connstr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
            SqlConnection  conn = new SqlConnection(connstr);
            conn.Open();

            查询数据

            SqlCommand com = new SqlCommand("select * from table", conn);
            SqlDataAdapter sda = new SqlDataAdapter(com);
            sda.Fill(dt);
            if (dt.Rows.Count > 0)
            {
              for (int j = 0; j < result.Rows.Count; j++)
                {
                  for (int i = 0; i < result.Columns.Count; i++)
                    {
              this.richTextBox1.AppendText(dt.Rows[j][i].ToString() + " ");
            }
            this.richTextBox1.AppendText("
            ");
            }
            }   
        •   修改,插入,更新
          SqlCommand command = new SqlCommand(sql, conn);
          command.ExecuteNonQuery();
    • 修改富文本框关键字颜色和字体
      •  修改富文本框中特定字符的颜色和字体,支持重复出现情况
        private void modifyFont(string p)
                {
                    string s = richTextBox1.Text;
                    int M = p.Length; int N = s.Length;
                    char[] ss = s.ToCharArray(), pp = p.ToCharArray();
                    for (int i = 0; i < N - M + 1; i++)
                    {
                        int j;
                        for (j = 0; j < M; j++)
                        {
                            if (ss[i + j] != pp[j]) break;
                        }
                        if (j == p.Length)
                        {
                            richTextBox1.Select(i, p.Length);
                            richTextBox1.SelectionColor = Color.Red;
                            richTextBox1.SelectionFont = new Font(Font, FontStyle.Bold);
                        }
                    }
                }
  • 相关阅读:
    Remote API(RAPI)之 文件管理
    vue前端框架

    托马斯彩色回旋
    VUE?
    cookie与session
    ajax前后端分离
    djangoIII
    Django少年
    django三板斧
  • 原文地址:https://www.cnblogs.com/nnavvi/p/5342349.html
Copyright © 2011-2022 走看看