MySQL is used in websites developed by Asp.net

Source: Internet
Author: User

Use mysql-connector-net-5.1.7-noinstall

 

Web. Config File Settings

<Deleetask>
<Add key = "connstr" value = "Server = fengsulei \ sql2005; database = new_tes; uid = sa; Pwd = sa"/>
<Add key = "yycc" value = "Server = localhost; database = ftdms; uid = root; Pwd = 123456"/>
</Appsettings>

 

 

In the bin folder

MySQL. Data. dll

 

 

Uniformly introduce Database Connection Files

 

 

Using system;
Using system. Data;
Using system. Data. sqlclient;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;

/// <Summary>
/// Database Class
/// </Summary>
Public class DB
{
Public String strconn = configurationsettings. receivettings ["connstr"];
}
Public class my
{
Public String mystr = configurationsettings. receivettings ["yycc"];
}

 

The method used on the page is similar to that used in the MSSQL database.

 

 

using system;
using system. data;
using MySQL. data;
using MySQL. data. mysqlclient;
using system. configuration;
using system. collections;
using system. web;
using system. web. security;
using system. web. ui;
using system. web. UI. webcontrols;
using system. web. UI. webcontrols. webparts;
using system. web. UI. htmlcontrols;

Public partial class MYSQL: system. web. UI. page
{< br> my DB = new my ();
protected void page_load (Object sender, eventargs E)
{< br> mysqlconnection mycon = new mysqlconnection (dB. mystr);
mycon. open ();
mysqlcommand mycmd = new mysqlcommand ("select * From ftdms_admin where id =? ID ", mycon);
{< br> mycmd. Parameters. addwithvalue ("? ID ", 1);

}
Mysqldatareader myreader = mycmd. executereader ();
While (myreader. Read ())
{
If (myreader. hasrows)
{
Response. Write (myreader. getstring ("admin_user") + "<br/> ");
}
}
Myreader. Close ();
Mycon. Close ();

}
}

 

OK.

 

 

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.