为什么我得到"无法找到类型"和#34;在当前环境中不存在"

时间:2016-02-28 03:23:03

标签: c# asp.net

我有两个问题:第一个是为什么我得到"无法找到类型或命名空间" - 参考行中的PostM

  

public PostM myPost = new PostM();

。第二个问题是,为什么,在下一行,我得到"名称BlogID在当前上下文中不存在"

  

myPost.displayPosts(BlogID);

namespace Assessment_2
{
    public partial class Addpost2 : System.Web.UI.Page
    {
        **public PostM myPost = new PostM()**; 
        string BlogID;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtBlogDate.Text = GridView1.SelectedRow.Cells[3].Text;
            txtBlogTitle.Text = GridView1.SelectedRow.Cells[2].Text;
            BlogID = GridView1.SelectedRow.Cells[1].Text;
        }

        protected void btnSavePost_Click(object sender, EventArgs e)
        {       
            string currentUserId = Context.User.Identity.GetUserId();
            string comment = txtComments.Text;
            string BlogID = GridView1.SelectedRow.Cells[1].Text;
            myPost.addPost(currentUserId, comment, BlogID, Label2);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            **myPost.displayPosts(BlogID);**
        }
    }
}

PostM.cs包含:

namespace Assessment_2
{
    public class PostM
    {
        private string title;
        private string description;
        private DateTime date;
        private SqlDataSource datasource;

    // Class Constructor - creates the object instance.  Invoked by "PostM myblog = new PostM()" - see .cs file

    public PostM()
    {
        this.title = "";
        this.description = "";
        this.date = new DateTime();
        datasource = new SqlDataSource();
    }

    // Procedural methods

    ..........etc

感谢。这是displayPosts方法:

public string displayPosts(string BlogID)
        {
            this.datasource.SelectCommand = "SELECT * FROM dbo.Post WHERE ";
            var result = this.datasource.Select(DataSourceSelectArguments.Empty);

            DataView reader = (DataView)result; // Cast result to DataView

            string posts = "";
            foreach (DataRow row in reader.Table.Rows)   // While DataView contains rows of data
            {
                posts += row["Post_id"].ToString()+",";
                posts += row["Member_id"].ToString() + ",";
                posts += row["Post_Comments"].ToString() + ",";
                posts += row["Post_Date"].ToString() + ",";
                posts += row["Post_Time"].ToString() + ",";
            }
            return posts;
        }

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Addpost2.aspx.cs" Inherits="Assessment_2.Addpost2" %>  

我通过重建项目解决了这个问题...感谢您的帮助。

0 个答案:

没有答案