小编Ang*_*ina的帖子

非静态字段,方法或属性'System.Web.UI.Page.Session.get'需要对象引用

我得到的错误就像

非静态字段,方法或属性'System.Web.UI.Page.Session.get'需要对象引用

你能建议我在会话中从这个问题中恢复吗?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Web.SessionState;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //Onclick Submit Button
    [WebMethod(EnableSession = true)]
    //[System.Web.Services.WebMethod(EnableSession = true)]
    public static string Login(string email, string password)
    {
        var con = new SqlConnection(ConfigurationManager.ConnectionStrings["blogConnString"].ConnectionString);
        con.Open();
        string res = "0";
        SqlDataReader reader;       
        string sql = "select uid,username from personal where email='" + email + "' …
Run Code Online (Sandbox Code Playgroud)

c# asp.net session webmethod

4
推荐指数
2
解决办法
3万
查看次数

如何限制数据集中的行数

参考代码

 [WebMethod]

 public static string GetData()
 {
      string query = "SELECT * FROM tblCountry";
      SqlCommand cmd = new SqlCommand(query);
      return GetData(cmd).GetXml();
 }
 private static DataSet GetData(SqlCommand cmd)
 {
      string strConnString = @"Data Source=.\sqlExpress;Initial Catalog=dbTest;Integrated  Security=SSPI; pooling=false";
      using (SqlConnection con = new SqlConnection(strConnString))
      {
          using (SqlDataAdapter sda = new SqlDataAdapter())
          {
             cmd.Connection = con;
             sda.SelectCommand = cmd;
             using (DataSet ds = new DataSet())
             {
                sda.Fill(ds);
                return ds;
             }
          }
      }
 } 
Run Code Online (Sandbox Code Playgroud)

在以下位置查看更多信息:链接

查询返回20行,我需要单独显示10行。在查询中没有任何更改的情况下,就有可能限制数据集中的数据。

c# asp.net dataset sqldataadapter

2
推荐指数
1
解决办法
5132
查看次数

标签 统计

asp.net ×2

c# ×2

dataset ×1

session ×1

sqldataadapter ×1

webmethod ×1