static void Main(string[] args) { // Create the connection to the resource! // This is the connection, that is established and // will be available throughout this block. using (SqlConnection conn = new SqlConnection()) { // Create the connectionString // Trusted Connection is used to denote that the connection uses Windows Authentication conn.ConnectionString = "Server=[(local)];Database=[ModelDB];Trusted_Connection=true"; conn.Open(); // Create the command SqlCommand command = new SqlCommand("SELECT Alarms.Text, Routetable.Latitude, Routetable.Longitude FROM Alarms INNER JOIN Routetable ON Alarms.Text=Routetable.Location;", conn); using (SqlDataReader reader = command.ExecuteReader()) { Console.WriteLine("Text\t"); while (reader.Read()) { Console.WriteLine(String.Format("{0} \t ", reader[0])); } } Console.WriteLine("Coordinates displayed!!"); Console.ReadLine(); Console.Clear(); } // Final step, close the resources flush dispose them. ReadLine to prevent the console from closing. Console.ReadLine(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)