Last active
February 14, 2020 08:38
-
-
Save rakotomandimby/fa9215cb9a14123d9f93e5f8a7652e12 to your computer and use it in GitHub Desktop.
"Invoke-Sqlcmd" and "Install-Module" not available?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data.SqlClient; | |
namespace RKTMB { | |
class Program | |
{ | |
private static SqlConnection cnn; | |
public static void FetchAllNames() | |
{ | |
string connectionString = null; | |
connectionString = @"Server=sql-server.rktmb.org\dev;Database=Customers;User ID=RKTMB\MR01;Password=Madagasikara;Trusted_Connection=true;"; | |
cnn = new SqlConnection(connectionString); | |
try | |
{ | |
cnn.Open(); | |
SqlCommand command = new SqlCommand("SELECT DISTINCT [Name] FROM [Customers].[dbo].[Customers]", cnn); | |
SqlDataReader reader = command.ExecuteReader(); | |
while (reader.Read()) | |
{ | |
Console.WriteLine("This is hat I read:\t{0}", reader.GetString(0)); | |
} | |
cnn.Close(); | |
Console.ReadLine(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Exception"); | |
Console.ReadLine(); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
FetchAllNames(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment