Poc-asp.net & MySQL Section

Source: Internet
Author: User
Tags connectionstrings

1. asp. NET with MySQL is required to introduce a MySQL package, which can be found in the VS tools-> extension Manager

2. Next is the configuration information in the Webconfig

  < connectionStrings >  <  name= "ConnStr"  connectionString= "User id=root;host=localhost;d atabase=test;password=1234; " ProviderName = "MySql.Data.MySqlClient" />  </ connectionStrings >

3.MYSQL C # Connection code

stringstrconn = configurationmanager.connectionstrings["ConnStr"].            ConnectionString; Mysqlconnection myconnection=Newmysqlconnection (strconn); Mysqlcommand mycommand=NewMysqlcommand (QUERY, myconnection);Myconnection.open (); Mysqldatareader MyDataReader=Mycommand.executereader ();  while(Mydatareader.read () = =true) {mydatareader[the field"].             ToString (); } mydatareader.close ();

4. Convert xlsx to Csv/txt, then data into MySQL

load data local infile "D:/intotable1 lines;

5. Some problems when working with MySQL data

5.1 Sort by specified order

Order  by InStr ('value,value,value,value'< field name >)

5.2 Need to create a calendar table as a secondary table, you need to write a procedure

CREATE TABLE' Tmpdate ' (datevarchar( -), Amountint(2));D elimiter $$DROP PROCEDURE IF EXISTSzj$$CREATE PROCEDUREZJ (i date,j DATE)BEGIN whileI<=J DoINSERT  into' Tmpdate 'VALUESI0);SETI=I+INTERVAL1  Day;END  while;END$ $DELIMITER; call ZJ ('2014-03-03','2015-12-31');Select *  from' Tmpdate ';

5.3 C # code in the SQL statement with variables in the connection problem, the following param1, is composed of ' "+param1 +" ', external single-cited, internal double-cited.

Query="Select *  from(Select *  fromTmpdatewhere  not EXISTS"+                     "(SelectDate fromWmissuewhereDate=Tmpdate. Date)Union(Select"+"Date,Count(*) from(Select *  fromWmissuewhereCustomer='  "+param1+"') BGroup  byDate)) AwhereDatebetween"+"Date_sub (Date_format (now),'%y-%m-%d'), Interval1Week andDate_format (now (),'%y-%m-%d')Order  byDate ";

Poc-asp.net & MySQL Section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.