-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass1.cs
35 lines (30 loc) · 1.06 KB
/
Class1.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
using System;
using Microsoft.Data.SqlClient;
class Program
{
static void Main(string[] args)
{
// Define the connection string
string connectionString = "Server=DESKTOP-M485FJE\\SQLEXPRESS;Database=QuizDB;Trusted_Connection=True;";
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("Connection established successfully!");
// Example: Fetch Users
string query = "SELECT * FROM Users;";
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"UserID: {reader["UserID"]}, UserName: {reader["UserName"]}, UserEmail: {reader["UserEmail"]}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}