Hello, I am new on c#, Iam trying to read data from MSSQL table using single .aspx file. now I am facing this Error CS0103. Compiler Error Message: CS0103: The name 'response' does not exist in the current context. <%@ Page Language="C#" Debug="true" %><%@ Import Namespace="System" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> class DataReader_SQL { [STAThread] public static void Main(string[] args) { try { SqlConnection thisConnection = new SqlConnection(@"Network Library=DBMSSOCN;Data Source=MyserverIP,1433;database=DBname; User id=DBuser;Password=DBpass;"); thisConnection.Open(); SqlCommand thisCommand = thisConnection.CreateCommand(); thisCommand.CommandText = "SELECT Num1, Num2 FROM z_TestSite"; SqlDataReader thisReader = thisCommand.ExecuteReader(); while (thisReader.Read()) { Console.WriteLine(thisReader["Num1"], thisReader["Num2"]); } thisReader.Close(); thisConnection.Close(); } catch (SqlException e) { Console.WriteLine(e.Message); } } } </script> PHP: Any Help Please ?
I believe you need to use response.write and not console.write. Console.write is for desktop applications, generally for quick debugging. Console.WriteLine(thisReader["Num1"], thisReader["Num2"]); should be Response.Write(thisReader["Num1"], thisReader["Num2"]); same with Console.WriteLine(e.Message);
What in the world is that? You state it is php code, but then the code is in asp.net, but actually trying to create a console app.