using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Using Mysql Namespace
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data;
namespace WindowsFormsApplication2
{
public class MySqlConn
{
#region ===== MySQL Connection =====
MySqlConnection _conn = new MySqlConnection();
string _connString = "Server=127.0.0.1;Database=DB명;Uid=계정명;pwd=비밀번호";
///
/// MySQL 연결
///
public void MySQLConnection()
{
try
{
_conn.ConnectionString = _connString;
_conn.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
///
/// MySQL 연결 해제
///
public void MySQLDisConnect()
{
if (_conn != null)
_conn.Close();
}
#endregion
public DataSet GetMemberList()
{
MySQLConnection();
string strQuery = "SELECT * FROM Member";
//_conn.ConnectionString = _connString;
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = _conn;
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(strQuery, _conn);
da.Fill(ds, "Member");
MySQLDisConnect();
return ds;
}
public int SetMemberList(string[] arrParam)
{
MySQLConnection();
string strQuery = "Insert Into Member(EMAIL, KOR_NM, PASSWORD) VALUES(@Email, @KOR_NM, @PWD)";
//_conn.ConnectionString = _connString;
MySqlCommand InsertCommand = new MySqlCommand();
InsertCommand.Connection = _conn;
InsertCommand.CommandText = strQuery;
InsertCommand.Parameters.Add("@Email", MySqlDbType.VarChar, 200);
InsertCommand.Parameters.Add("@KOR_NM", MySqlDbType.VarChar, 100);
InsertCommand.Parameters.Add("@PWD", MySqlDbType.VarChar, 100);
InsertCommand.Parameters[0].Value = arrParam[0];
InsertCommand.Parameters[1].Value = arrParam[1];
InsertCommand.Parameters[2].Value = arrParam[2];
int intResult = InsertCommand.ExecuteNonQuery();
MySQLDisConnect();
return intResult;
}
public DataSet GetIDCheck(string userID)
{
DataSet ds = null;
string strQuery = "SELECT EMail from Member Where Email='" + userID + "'";
MySQLConnection();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = _conn;
ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(strQuery, _conn);
da.Fill(ds, "Memeber");
MySQLDisConnect();
return ds;
}
}
}