【问题标题】:Getting error in Response响应中出现错误
【发布时间】:2013-01-16 06:19:09
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web;

namespace Database_Updation
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn1"].ToString());

            SqlCommand cmd = new SqlCommand("SELECT [GUID] FROM [Source].[dbo].[Source_User]", cn);
            cn.Open();
            SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            rdr.Read();
            Response.Write(rdr[0].ToString()); //read a value

        }
    }
}

我收到错误The name 'Response' does not exist in the current context

【问题讨论】:

  • 这看起来像一个控制台应用程序。您希望 Response 在这里出现什么?
  • 对不起,我忘了写控制台而不是响应

标签: c# asp.net .net dll


【解决方案1】:

尝试使用

Console.Write(rdr[0].ToString()); //Write a value 

代替

Response.Write(rdr[0].ToString()); //Write a value

希望对你有帮助

【讨论】:

    【解决方案2】:

    从你的代码来看,它是控制台应用程序,而不是使用响应,并且还检查数据读取器是否有数据

    if(rdr.Read())
      Console.Writeln(rdr[0].ToString());
    

    响应是 Web 应用程序中使用的对象,如果您愿意,您将在 asp.net Web 应用程序中获取此对象创建 Web 应用程序而不是控制台应用程序...您需要阅读控制台和 Web asp.net 之间的区别应用

    【讨论】:

      【解决方案3】:

      第一次检查参考 System.Web.dll 添加与否 和 尝试 System.Web.HttpContext.Current.Response.Write(rdr[0].ToString());

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多