-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
48 lines (42 loc) · 1.32 KB
/
Program.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
using System;
using System.Data;
using System.Data.SqlClient;
internal class Program
{
private static void Main(string[] args)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Server=tcp:s-bear42.database.windows.net,1433;Initial Catalog=db-helloWorld;Persist Security Info=False;User ID={insert your id};Password={insert your [password]};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
try
{
HasRows(con);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void HasRows(SqlConnection connection)
{
using (connection)
{
SqlCommand command = new SqlCommand(
"SELECT TOP (1000) * FROM [classicmodels].[customers]",
connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}\t{1}", reader.GetString(1), reader.GetString(10));
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}
}
}