public class TestResultDTO
{
public int id { get; set; }
public string name { get; set; }
public float score { get; set; }
}
insert and select
public class MysqlConnector
{
private MySqlConnection connection = new MySqlConnection("Server=severip;User ID=id;Password=password;Database=db_name;Port=port");
public MysqlConnector()
{
connection.Open();
}
public void MysqlConnectorSelect(string date)
{
List<TestResultDTO> resultList = new List<TestResultDTO>();
if (connection.State != System.Data.ConnectionState.Open) connection.Open();
string sql = "select id , table_name.NAME ,score from table_name where score >= 85 ";
var command = new MySqlCommand(sql, connection);
// command.CommandTimeout = 9000000;
var reader = command.ExecuteReader();
while (reader.Read())
{
TestResultDTO result = new TestResultDTO();
result.Name = reader.GetInt32(0);
result.Detecttime = reader.GetString(1);
result.Countvalue = reader.GetFloat(2);
resultList.Add(result);
}
// Console.WriteLine(resultList.Count());
connection.Close();
}
public void MysqlConnectorInsert(TestResultDTO result)
{
string insertQuery = String.Format("INSERT INTO table_name (id,name,score) VALUES('{0}','{1}','{2}')"
, result.id, result.name, result.score);
MySqlCommand command = new MySqlCommand(insertQuery, connection);
//if (command.ExecuteNonQuery() == 1)
//{
// Console.WriteLine("인서트 성공");
//}
//else
//{
// Console.WriteLine("인서트 실패");
//}
}
}
'C# > c#' 카테고리의 다른 글
[ c# ] 매일 밤 12시 폴더 생성 , 폴더 삭제 Task 이용 (0) | 2022.12.28 |
---|---|
[ c# ] EF Core vs Dapper vs MySqlConnecter 성능 비교 (0) | 2022.12.27 |
[ c# ] Dapper 사용해서 mysql select , insert (0) | 2022.12.24 |
[ c# ] ini 파일 읽어오는 법 2가지 (1) | 2022.12.22 |
[ open API ] open API _ 공공 데이터 포털 xml 데이터 가져오기 (0) | 2021.11.17 |