• 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);
                        }
                    }
                }
  • 相关阅读:
    阿里图标库引用简介---20200608更新
    2.10排序算法
    2.9Node节点的学习
    2.8DOM节点的学习
    2.5数组
    2.6对象和函数
    2.7变量、内存、Math和Date的初级认识
    css优先级问题
    事件委托(事件代理)初认识
    静态页面学习随笔(1)-如何正确布局大体结构
  • 原文地址:https://www.cnblogs.com/nnavvi/p/5342349.html
Copyright © 2020-2023  润新知