• POC


    1. ASP.NET 用MYSQL是需要引入MYSQL的包的,这个在VS的TOOLS-> extension manager里可以搜到的

    2. 接下来是WEBCONFIG里的配置信息

      <connectionStrings>
      <add name="connStr" connectionString="User Id=root;host=localhost;Database=test;password=1234;" providerName="MySql.Data.MySqlClient"/>
      </connectionStrings>

    3.MYSQL C#连接代码

    string strConn = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
                MySqlConnection myConnection = new MySqlConnection(strConn);
                MySqlCommand myCommand = new MySqlCommand(QUERY, myConnection);
                myConnection.Open();
                MySqlDataReader myDataReader = myCommand.ExecuteReader();
                while (myDataReader.Read() == true)
                {
                    myDataReader["字段"].ToString();             
                }
                myDataReader.Close();

    4. 将XLSX转换成CSV/TXT,然后数据导入MYSQL

    load data local infile "d:/sql.txt" into table <table_name> ignore 1 lines;

    5.在处理MYSQL数据时遇到的一些问题

      5.1 按指定顺序排序

    order by instr('value,value,value,value', <字段名>

      5.2 需要创建一个日历表来作为辅助表,需要写个procedure

    CREATE TABLE `tmpdate` (date varchar(20),amount int(2));
    DELIMITER $$
    DROP PROCEDURE IF EXISTS zj$$
    CREATE PROCEDURE zj(i DATE,j DATE)
    BEGIN
    WHILE i<=j DO
    INSERT INTO `tmpdate` VALUES(i,0);
    SET i=i+INTERVAL 1 DAY;
    END WHILE;
    END$$
    DELIMITER ;
    
    call zj('2014-03-03','2015-12-31');
    select * from `tmpdate`;

       5.3 C#代码中sql语句中带变量的连接问题,如下param1,是由' " +param1 + " ' 组成,外单引,内双引。

    query = "select * from (select * from tmpdate where NOT EXISTS" +
                         "(select Date from wmissue where Date=tmpdate.Date) union(select " +
                         "Date,count(*) from (select * from wmissue where Customer='"+param1+"') B group by Date)) A where Date between " +
                         "DATE_SUB(DATE_FORMAT(now(),'%Y-%m-%d'),interval 1 week) and DATE_FORMAT(now(),'%Y-%m-%d') order by Date";
  • 相关阅读:
    队列
    使用JPype实现Python调用JAVA程序
    Django和Flask对于URL尾斜杠(back slash)的处理
    数据仓库建设中的数据建模方法(转)
    python自定义logger handler
    Eclipse下.project和.classpath作用(转)
    理解python的with语句
    django常见小问题收集(转)
    windows下无法创建django工程的问题
    Excel的python读写
  • 原文地址:https://www.cnblogs.com/kiddy/p/4351841.html
Copyright © 2020-2023  润新知