먼저 MySQL Connector/net을 다운받습니다.
https://dev.mysql.com/downloads/connector/net/8.0.html
프로젝트에 MySQL 을 추가합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace WindowsFormsApp1
{
class DAO
{
const string url = "Server=localhost;Database=test;Uid=root;Pwd=1234;Charset=utf8";
static int boardCount { get; set; }
internal int selectCount()
{
using (MySqlConnection conn = new MySqlConnection(url))
{
conn.Open();
string sql = "SELECT count(*) cnt FROM freeboard";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
boardCount = Convert.ToInt32(rdr["cnt"].ToString());
rdr.Close();
return boardCount;
}
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace WindowsFormsApp1
{
class MessageBot
{
private DAO dao { get; set; }
public MessageBot(DAO dao)
{
this.dao = dao;
}
public void BotCall(object sender, EventArgs e)
{
int boardCount = dao.selectCount();
Console.WriteLine(boardCount);
}
}
}
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
internal LetterVO newLetter()
{
using (MySqlConnection conn = new MySqlConnection(url))
{
conn.Open();
string sql = "SELECT * from FROM letter where id = (select max(id) from letter)";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
LetterVO letterVO = new LetterVO();
letterVO.getter_setter_id = Convert.ToInt32(rdr["id"].ToString());
rdr.Close();
return letterVO;
}
} |
cs |
'텔레그램 API 사용하기' 카테고리의 다른 글
C# 에서 텔레그램 API 사용하기 (0) | 2018.08.03 |
---|
댓글