zoukankan      html  css  js  c++  java
  • 计数数据存入Mysql

    引用dll

    MySql.Data.dll

    建一个数据连接静态类

    public static class mysql
    {
    public static string constr = "database=test;Password=密码;user ID=root;server=ip地址";
    public static MySqlConnection conn = new MySqlConnection(constr);
    }

    //定义测试字段

    double countpass;
    double countfail;

    读取数据库数量方法 

      getcount();

    private void getcount()
    {


    countfail = 0;
    countpass = 0;
    mysql.conn.Open();//打开数据库
    MySqlCommand cons = new MySqlCommand("select * from testlog where 时间 = '" + System.DateTime.Now.ToString("yyyy-MM-dd") + "'and 机型 = 'xxxx'and 站别='"+ comboBox1 .Text+ "'", mysql.conn);//
    MySqlDataReader readers = cons.ExecuteReader();
    if (readers.Read())
    {
    countpass = Convert.ToInt32(readers[1].ToString());
    countfail = Convert.ToInt32(readers[2].ToString());
    }
    else
    {
    countpass = 0;
    countfail = 0;
    mysql.conn.Close();
    mysql.conn.Open();
    string sqlstr = "insert into testlog values('xxxx','" + 0 + "','" + 0 + "','" + 0 + "','" + System.DateTime.Now.ToString("yyyy-MM-dd") + "','" + comboBox1.Text + "')";
    MySqlCommand comm = new MySqlCommand(sqlstr, mysql.conn);
    comm.ExecuteNonQuery();
    countpass = 0;
    countfail = 0;
    mysql.conn.Close();
    }
    mysql.conn.Close();
    label14.Text = Convert.ToString(countfail + countpass);
    label5.Text = Convert.ToString(countpass);
    label6.Text = Convert.ToString(countfail);


    }

    //存入数据

    private void count()
    {
    if (ConsTant.test == 2)
    {

    }
    else
    {
    mysql.conn.Open();//打开数据库
    double Num = countpass + countfail;
    string sqlstr = "update testlog set 成功数 = '" + countpass + "', 失败数 = '" + countfail + "', 总数 ='" + Num + "' where 时间='" + System.DateTime.Now.ToString("d") + "' and 站别='" + comboBox1.Text + "'and 机型 = 'xxx'";
    MySqlCommand comm = new MySqlCommand(sqlstr, mysql.conn);
    int iRet = comm.ExecuteNonQuery();
    mysql.conn.Close();
    //label14.Text = Convert.ToString(countfail + countpass);
    //label5.Text = Convert.ToString(countpass);
    //label6.Text = Convert.ToString(countfail);
    }
    }

  • 相关阅读:
    JAVA 字符处理
    android:visibility 隐藏 可见 不可见
    Android中 int 和 String 互相转换的多种方法
    日期月和日补零
    【程序】程序报错 error:-1610149839 等大负数
    【IE】将IE11改为64位
    【linux】CentOS网络配置
    【linux】CentOS虚拟机eth0 提示Device does not seem to be present
    【SUSE】关闭防火墙
    【走马观花】十月八日通州雾
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/10916761.html
Copyright © 2011-2022 走看看