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);
                        }
                    }
                }
  • 相关阅读:
    「Poetize7」Freda的访客
    「Poetize8」Divisible
    「Poetize5」Vani和Cl2捉迷藏
    1082. 员工的重要度
    1080. 最大的岛
    1079. 连续子串计数(经典)
    1078. 数组的度
    1071. 词典中最长的单词
    1068. 寻找数组的中心索引
    1062. 洪水填充(经典)
  • 原文地址:https://www.cnblogs.com/nnavvi/p/5342349.html
Copyright © 2011-2022 走看看