Console.WriteLine - need help
-
Hello, I am trying to run this program in VS 2003. This runs fine but I can't see the results in Vs 2003. Infact I am not using any grid or any thing like that but using Console.WriteLine to print the results. I know that this program prints in the command prompt but I am trying to find an option so that I can see the results in VS 2003 (either command window or any other window). Is there any other line of code that I can use to print the results in VS 2003? static void Main() { //Application.Run(new Form1()); // 1. Instantiate the connection string Connection; Connection = "Data Source='TestServer';Initial Catalog=Northwind;Trusted_Connection=sspi"; //Connection = "Data Source='TestServer';Initial Catalog=Northwind;User id=sa;Pwd=development"; SqlConnection conn = new SqlConnection(Connection); SqlDataReader rdr = null; try { // 2. Open the connection conn.Open(); // 3. Pass the connection to a command object SqlCommand cmd = new SqlCommand("select * from Customers", conn); // // 4. Use the connection // // get query results rdr = cmd.ExecuteReader(); // print the CustomerID of each record while (rdr.Read()) { //Console.WriteLine(rdr[0]); System.Console.WriteLine(rdr[0]); } } catch (Exception ex) { throw ex; } finally { // close the reader if (rdr != null) { rdr.Close(); } // 5. Close the connection if (conn != null) { conn.Close(); } } }
-
Hello, I am trying to run this program in VS 2003. This runs fine but I can't see the results in Vs 2003. Infact I am not using any grid or any thing like that but using Console.WriteLine to print the results. I know that this program prints in the command prompt but I am trying to find an option so that I can see the results in VS 2003 (either command window or any other window). Is there any other line of code that I can use to print the results in VS 2003? static void Main() { //Application.Run(new Form1()); // 1. Instantiate the connection string Connection; Connection = "Data Source='TestServer';Initial Catalog=Northwind;Trusted_Connection=sspi"; //Connection = "Data Source='TestServer';Initial Catalog=Northwind;User id=sa;Pwd=development"; SqlConnection conn = new SqlConnection(Connection); SqlDataReader rdr = null; try { // 2. Open the connection conn.Open(); // 3. Pass the connection to a command object SqlCommand cmd = new SqlCommand("select * from Customers", conn); // // 4. Use the connection // // get query results rdr = cmd.ExecuteReader(); // print the CustomerID of each record while (rdr.Read()) { //Console.WriteLine(rdr[0]); System.Console.WriteLine(rdr[0]); } } catch (Exception ex) { throw ex; } finally { // close the reader if (rdr != null) { rdr.Close(); } // 5. Close the connection if (conn != null) { conn.Close(); } } }
-
Hello, I am trying to run this program in VS 2003. This runs fine but I can't see the results in Vs 2003. Infact I am not using any grid or any thing like that but using Console.WriteLine to print the results. I know that this program prints in the command prompt but I am trying to find an option so that I can see the results in VS 2003 (either command window or any other window). Is there any other line of code that I can use to print the results in VS 2003? static void Main() { //Application.Run(new Form1()); // 1. Instantiate the connection string Connection; Connection = "Data Source='TestServer';Initial Catalog=Northwind;Trusted_Connection=sspi"; //Connection = "Data Source='TestServer';Initial Catalog=Northwind;User id=sa;Pwd=development"; SqlConnection conn = new SqlConnection(Connection); SqlDataReader rdr = null; try { // 2. Open the connection conn.Open(); // 3. Pass the connection to a command object SqlCommand cmd = new SqlCommand("select * from Customers", conn); // // 4. Use the connection // // get query results rdr = cmd.ExecuteReader(); // print the CustomerID of each record while (rdr.Read()) { //Console.WriteLine(rdr[0]); System.Console.WriteLine(rdr[0]); } } catch (Exception ex) { throw ex; } finally { // close the reader if (rdr != null) { rdr.Close(); } // 5. Close the connection if (conn != null) { conn.Close(); } } }
-
Hello, I am trying to run this program in VS 2003. This runs fine but I can't see the results in Vs 2003. Infact I am not using any grid or any thing like that but using Console.WriteLine to print the results. I know that this program prints in the command prompt but I am trying to find an option so that I can see the results in VS 2003 (either command window or any other window). Is there any other line of code that I can use to print the results in VS 2003? static void Main() { //Application.Run(new Form1()); // 1. Instantiate the connection string Connection; Connection = "Data Source='TestServer';Initial Catalog=Northwind;Trusted_Connection=sspi"; //Connection = "Data Source='TestServer';Initial Catalog=Northwind;User id=sa;Pwd=development"; SqlConnection conn = new SqlConnection(Connection); SqlDataReader rdr = null; try { // 2. Open the connection conn.Open(); // 3. Pass the connection to a command object SqlCommand cmd = new SqlCommand("select * from Customers", conn); // // 4. Use the connection // // get query results rdr = cmd.ExecuteReader(); // print the CustomerID of each record while (rdr.Read()) { //Console.WriteLine(rdr[0]); System.Console.WriteLine(rdr[0]); } } catch (Exception ex) { throw ex; } finally { // close the reader if (rdr != null) { rdr.Close(); } // 5. Close the connection if (conn != null) { conn.Close(); } } }
There is only one way to do this. Write the output into a text file and open that file in the VS 2003 at run time. I hope, you got answer for your question.
Sr. Software Engineer Irevna, India