-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogram.cs
More file actions
42 lines (38 loc) · 1.33 KB
/
program.cs
File metadata and controls
42 lines (38 loc) · 1.33 KB
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
using System;
using System.Data.Odbc;
namespace ODBCDemo
{
class Program
{
static void Main(string[] args)
{
// TODO: Replace with your actual DSN, username, and password
string connStr = "DSN=sqllu-uda10;UID=openlink;PWD=Odbc@mssql;";
Console.WriteLine($"Using connection: {connStr}");
using (OdbcConnection conn = new OdbcConnection(connStr))
{
try
{
conn.Open();
Console.WriteLine("Connected to database via ODBC DSN!");
// TODO: Replace with a valid SQL query for your database
string sql = "SELECT TOP 5 * FROM Customers";
using (OdbcCommand cmd = new OdbcCommand(sql, conn))
using (OdbcDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
// Example: print first column
Console.WriteLine(reader[0].ToString());
}
}
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
}
}