-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass2.cs
60 lines (51 loc) · 1.42 KB
/
Class2.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Leaernify
{
internal class Class1
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Learnify;Integrated Security=True;");
SqlCommand cmd;
public Class1()
{
getData();
}
public void getData()
{
try
{
con.Open();
cmd = new SqlCommand("SELECT * FROM users", con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string username = reader.GetString(1);
string email = reader.GetString(2);
Console.WriteLine($"ID: {id}, Username: {username}, Email: {email}");
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("Terjadi kesalahan: " + ex.Message);
}
finally
{
con.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}