Skip to content

Instantly share code, notes, and snippets.

@rakotomandimby
Last active February 14, 2020 08:38
Show Gist options
  • Save rakotomandimby/fa9215cb9a14123d9f93e5f8a7652e12 to your computer and use it in GitHub Desktop.
Save rakotomandimby/fa9215cb9a14123d9f93e5f8a7652e12 to your computer and use it in GitHub Desktop.
"Invoke-Sqlcmd" and "Install-Module" not available?
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