Skip to main content
 首页 » 编程设计

c#之在响应中出现错误

2024年02月20日12unruledboy

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 
 
        } 
    } 
} 

我收到错误消息当前上下文中不存在名称“Response”

请您参考如下方法:

尝试使用

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

代替

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

希望对你有帮助