程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> asp.net-新手ASP.NET編程問題求解

asp.net-新手ASP.NET編程問題求解

編輯:編程綜合問答
新手ASP.NET編程問題求解

列名 'zz' 無效。

說明: 執行當前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。

異常詳細信息: System.Data.SqlClient.SqlException: 列名 'zz' 無效。

源錯誤:

行 27: SqlCommand comm = new SqlCommand(sql1, conn);
行 28: DataSet ds = new DataSet();
行 29: SqlDataReader dr = comm.ExecuteReader();
行 30: if (dr.Read())
行 31: {

源文件: f:\C#\注冊登陸\用戶頁面.aspx.cs 行: 29

堆棧跟蹤:

[SqlException (0x80131904): 列名 'zz' 無效。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2436614
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) +5731148
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +628
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
System.Data.SqlClient.SqlCommand.ExecuteReader() +99
Default2.Page_Load(Object sender, EventArgs e) in f:\C#\注冊登陸\用戶頁面.aspx.cs:29
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2952

版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.6.1038.0

    SqlConn sc = new SqlConn();
    protected void Page_Load(object sender, EventArgs e)
{
    Label10.Text=Session["name"].ToString();
    string sql1 = "select * from XX where Name=" + Session["name"] + "";
    SqlConnection conn = sc.getSqlConnection();
    conn.Open();

    SqlCommand comm = new SqlCommand(sql1, conn);
    DataSet ds = new DataSet();
    SqlDataReader dr = comm.ExecuteReader();
    if (dr.Read())
    {
        this.Label11.Text = dr.GetString(dr.GetOrdinal("Nicename"));
        this.Label12.Text = dr.GetString(dr.GetOrdinal("Sex"));
        this.Label13.Text = dr.GetString(dr.GetOrdinal("PhoneNumber"));
        this.Label14.Text = dr.GetString(dr.GetOrdinal("Email"));
    }


最佳回答:


sql語句估計有錯誤,你把最終的sql打印出來看看

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved