Asp. NET no magic--asp.net MVC and database MySQL

Source: Internet
Author: User

This article describes how my blog uses ADO to access SQL Server to get data. This chapter describes how to use my SQL to complete data management.
Before using my SQL, you need to ensure that the my SQL database and connector/net are installed in the development environment, which is an ADO data provider written in C #, in other words, whether you use SQL Server or my sql,asp. NET is to access, manipulate the database through ADO, the only difference is the data provider, so the connection to my SQL still needs to use the type in System.Data.dll, the following is described in the previous article:

 

The only difference is that the My SQL ADO data provider is required to install connector/net.

installing my SQL and connector/net

connector/net:https://dev.mysql.com/downloads/windows/installer/
MySQL (You can choose to install connector/net directly at installation): https://dev.mysql.com/downloads/mysql/

Add data tables and data when finished:

  

Create a new warehousing project for my SQL

The reason for creating a new project for it is to have SQL Server coexist with my SQL, which does not affect each other, and can be used to switch the database for use by simple modifications later on.

1. Create a new Class library project Blogrepository.mysql, and reference mysql.data (note: mysql.data need to install connector/net):

  

  

2. Implement a blogrepository using the Execute SQL method:

  

  

  

Compared to the code in SQL Server, only the object names, SQL, and connection strings differ.

3. Change the reference to the logical layer, use blogrepository.mysql, and modify the wrong namespace:

  

  

4. Run the program:

  

   

Summary:
This chapter describes how to use the MySQL database in ASP, which is basically the same as SQL Server, just install the components you need to connect to my SQL. Another point to note is that there are now blogrepository and blogrepository.mysql two repositories in the entire solution, respectively, for SQL Server and my SQL but only one for the logical layer, This means that each time you replace the database business logic library, you need to change not only the reference but also the code. This is a typical dependency implementation without relying on abstraction. This issue will be followed by a workaround.

Reference:

Https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting.html

This article connects: http://www.cnblogs.com/selimsong/p/7655042.html

Asp. NET no magic--Directory

Asp. NET no magic--asp.net MVC and database MySQL

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.