- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Data.SqlClient;
- namespace BrucesConsoleApp {
- class Program {
- static void Main(string[] args) {
- try {
- // Create the connection object
- SqlConnection connection = new SqlConnection();
- connection.ConnectionString = "Data Source=(localdb)\\MSSQLLocalDB;" +
- "Initial Catalog=Books;Integrated Security=True";
- // Create the command object and set the connection,
- // SELECT statement
- SqlCommand selectCommand = new SqlCommand();
- selectCommand.Connection = connection;
- selectCommand.CommandText = "SELECT * FROM Books";
- selectCommand.CommandType = System.Data.CommandType.Text;
- // Open the connection to the database
- connection.Open();
- SqlDataReader reader = selectCommand.ExecuteReader();
- if (reader.Read()) {
- Console.WriteLine($ "{reader.GetString(1)} {reader.GetString(2)}");
- Console.WriteLine($ "");
- }
- reader.Close();
- // Close the connection to the database
- connection.Close();
- } catch (Exception e) {
- Console.WriteLine($ "Error");
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Loading
Bruce ZelenkaPosted Aug 15, 2019, 6:42 PM
Bruce ZelenkaPosted Aug 15, 2019, 5:59 PM
Guest UserPosted Aug 15, 2019, 9:13 AM