반응형

ASP.NET에서 MySQL 연결

 

  • Version : ASP.NET (VS 2013)

 

ASP.NET에서 MySQL 연결 방법에 대해서 알아본다.

 

MySQL에 연결하기 위해서 NuGet 패키지에서 MySQL DLL 을 추가한다. VS 2013 툴 목록에서 [프로젝트] – [NuGet 패키지 관리]를 클릭한다.

 

 

NuGet 패키지 관리 창이 나타나면 mysql dll을 검색하여 설치한다.

 

 

MySQL DLL을 설치하면 Web.config 파일에 자동으로 MySQL Data Provider이 생성된 것을 확인 할 수 있다.

 

 

MySQL에 연결하여 데이터 입력 하기.

public string insertuser(DateTime RegDate, Int32 Num, string Conn)

{

 

// For MYSQL Authentication

MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new MySql.Data.MySqlClient.MySqlConnection();

mySqlConnection.ConnectionString = @"Data Source=iDataSource; Database=DB_Name; User ID=iUser; Password='iPass'";

MySql.Data.MySqlClient.MySqlCommand mySQLComand = mySqlConnection.CreateCommand();

mySqlConnection.Open();

mySQLComand.CommandText = "INSERT INTO tbl_a (RegDate, Num) VALUES (@RegDate, @Num)";

// Add Parameters to Command Parameters collection

 

mySQLComand.Parameters.Add("@RegDate", MySql.Data.MySqlClient.MySqlDbType.DateTime);

mySQLComand.Parameters.Add("@Num", MySql.Data.MySqlClient.MySqlDbType.Int16);

 

 

mySQLComand.Parameters["@RegDate"].Value = RegDate;

mySQLComand.Parameters["@Num"].Value = Num;

 

 

mySQLComand.ExecuteNonQuery();

return "done";

 

 

}

 

 

 

 

2015-04-29 / 강성욱 / http://sqlmvp.kr

 

 

ASP.NET, ASP.NET connect to MySQL, MySQL연결, DB연결, ASP to DB, IIS, MySQL, WebServer, 웹프로그래밍, ASP 프로그래밍

반응형

'SW Engineering > Programming' 카테고리의 다른 글

C# 가비지 컬렉터  (0) 2015.07.22
  (0) 2015.07.22

+ Recent posts