想采用三层架构思路来构建一个页面,要实现读取记录并显示出来的功能
其中:
WEB_MSDI_NEWS 是数据表
包含 Id,Title,Content字段1.数据访问层 public class NewsEdit
    {
        SqlConnection thisConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionsqlserver"].ConnectionString);
        public DataSet GetNews(string Id)
        {
            try
            {
                DataSet thisDataSet = new DataSet();
                thisConnection.Open();
                SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT Title,Content FROM WEB_MSDI_NEWS WHERE (Id = '"+Id+"')", thisConnection);
                SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
                thisAdapter.Fill(thisDataSet, "WEB_MSDI_NEWS");
                thisConnection.Dispose();
                return thisDataSet;
            }
            catch
            {
                throw;
            }
            finally
            {
                thisConnection.Close();
            }
        }
}
2.业务层 public class NewsEdit
    {
        IndexDAL.NewsEdit newsEdit = new IndexDAL.NewsEdit();
        //string message = string.Empty;
        //string Fid1 = string.Empty;        public DataSet GetNews(string Id)
        {
           DataSet getnews = newsEdit.GetNews(Id);
           return getnews;
        }
     }
3.表示层后台  this.TextBox1.Text = newsEdit.GetNews(id).Tables[0].Rows[0]["Content"].ToString();
但是在运行是总提示这个错误跟代码也不晓得是什么问题,恳请各位高手解答下

解决方案 »

  1.   

    newsEdit.GetNews(id).Tables[0].Rows[0]["Content"].ToString();错误太明显了 不想多说
    自己跟踪代码 到这行  仔细看看 就知道原因了
      

  2.   

    是的,已经跟踪了
    newsEdit.GetNews(id).Tables[0].Rows[0]["Content"].ToString();
    没有数据,应该怎样修改呢?
      

  3.   

    newsEdit.GetNews(id).Tables[0].Rows[0]["Content"].ToString();
    这句里面的东东都是能点出来的吗?
    还是自己强行写出来的??
      

  4.   

    public class NewsEdit
        {
            SqlConnection thisConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionsqlserver"].ConnectionString);
            public DataSet GetNews(string Id)
            {
                try
                {
                    DataSet thisDataSet = new DataSet();
                    thisConnection.Open();
                    SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT Title,Content FROM WEB_MSDI_NEWS WHERE (Id = '"+Id+"')", thisConnection);
                    SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
                    thisAdapter.Fill(thisDataSet, "WEB_MSDI_NEWS");
                    thisConnection.Dispose();
                     //在这里进行判断
                       if(thisDataSet.Tables[0].Rows.Count>0)                return thisDataSet;
                }
                catch
                {
                    throw;
                }
                finally
                {
                    thisConnection.Close();
                }
            }
    }