Created
April 21, 2018 11:25
-
-
Save otakijae/be1ed3e9c722383962e5dc53c2bf3de6 to your computer and use it in GitHub Desktop.
C#MySQLConnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using MySql.Data.MySqlClient; | |
namespace LecturePractice | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write("\n\n\t\t▶ "); string id = Console.ReadLine(); | |
Console.Write("\t\t▶ "); string password = Console.ReadLine(); | |
Console.Write("\t\t▶ "); string name = Console.ReadLine(); | |
String databaseConnect; | |
MySqlConnection connect; | |
databaseConnect = "Server=localhost;Database=bookmanage;Uid=study;Pwd=0000"; | |
connect = new MySqlConnection(databaseConnect); // conncet MySQL | |
connect.Open(); // open MySQL | |
String sql = "insert into member values('" + id + "', '" + password + "', '" + name + "');"; | |
MySqlCommand command = new MySqlCommand(sql, connect); // command | |
if (command.ExecuteNonQuery() == 1) | |
{ | |
Console.Clear(); | |
Console.WriteLine("\n\n\n\n"); | |
Console.WriteLine("\t\tInsert " + id); | |
Thread.Sleep(1000); | |
} | |
else | |
{ | |
Console.Clear(); | |
Console.WriteLine("Database Error!!"); | |
Thread.Sleep(1000); | |
} | |
sql = "select * from member;"; | |
command = new MySqlCommand(sql, connect); | |
MySqlDataReader reader = command.ExecuteReader(); | |
while (reader.Read()) | |
{ | |
id = reader["id"].ToString(); | |
password = reader["pwd"].ToString(); | |
name = reader["name"].ToString(); | |
MemberVO member = new MemberVO(id, password, name); | |
Console.WriteLine("\t\t" + member.PrintMember()); | |
} | |
reader.Close(); | |
connect.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment