想采用三层架构思路来构建一个页面,要实现读取记录并显示出来的功能
其中:
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();
但是在运行是总提示这个错误跟代码也不晓得是什么问题,恳请各位高手解答下
其中:
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();
但是在运行是总提示这个错误跟代码也不晓得是什么问题,恳请各位高手解答下
解决方案 »
- 怎么得到excel中对应的值?
- 如何播发Flash
- 自定义模板的数据绑定的GridView如何实现翻页功能?急!高分!
- 电玩巴士招聘 .net开发工程师
- 如何实现gridview无刷新的编辑、更新。。不是AJAX的
- *******请教转成ASPX规范写法*****
- 搜索结果显示在GridView的问题
- webrequest和webresponse的问题!!
- 用最简单的水晶报表例子,老是错误,为什么?
- 微信企业号开发 echostr校验失败,请您检查是否正确解密并输出明文echostr
- 请问.NET中关于页面URL这种情况怎么实现?
- 用VS2005调试运行和把代码挂到IIS上用IE浏览器运行有什么区别
自己跟踪代码 到这行 仔细看看 就知道原因了
newsEdit.GetNews(id).Tables[0].Rows[0]["Content"].ToString();
没有数据,应该怎样修改呢?
这句里面的东东都是能点出来的吗?
还是自己强行写出来的??
{
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();
}
}
}