SelectCommand.Connection 属性尚未初始化.
下面是代码//获取新闻列表(自动获取类型和数量)publicDataSetNewsList(intNewsCount,intNewsType){SqlHelpsh=new...
下面是代码
//获取新闻列表(自动获取类型和数量)
public DataSet NewsList(int NewsCount, int NewsType)
{
SqlHelp sh = new SqlHelp();
DataSet ds = new DataSet();
try
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select top @NewsCount" + "* from News where NewsType=@NewsType order by NewsId desc";
cmd.Parameters.Add("@NewsCount", OleDbType.Integer).Value = NewsCount;
cmd.Parameters.Add("@NewsType", OleDbType.Integer).Value = NewsType;
OleDbDataAdapter sda = new OleDbDataAdapter(cmd);
sda.Fill(ds, "News");
}
catch (OleDbException ex)
{
Console.Write(ex.Message);
}
finally
{
sh.Conn.Close();
}
return ds;
}
调用 JsxwList.DataSource = news.NewsList(4,3);
JsxwList.DataBind();
这里报错 提示Fill: SelectCommand.Connection 属性尚未初始化。
求讲解...... 展开
//获取新闻列表(自动获取类型和数量)
public DataSet NewsList(int NewsCount, int NewsType)
{
SqlHelp sh = new SqlHelp();
DataSet ds = new DataSet();
try
{
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select top @NewsCount" + "* from News where NewsType=@NewsType order by NewsId desc";
cmd.Parameters.Add("@NewsCount", OleDbType.Integer).Value = NewsCount;
cmd.Parameters.Add("@NewsType", OleDbType.Integer).Value = NewsType;
OleDbDataAdapter sda = new OleDbDataAdapter(cmd);
sda.Fill(ds, "News");
}
catch (OleDbException ex)
{
Console.Write(ex.Message);
}
finally
{
sh.Conn.Close();
}
return ds;
}
调用 JsxwList.DataSource = news.NewsList(4,3);
JsxwList.DataBind();
这里报错 提示Fill: SelectCommand.Connection 属性尚未初始化。
求讲解...... 展开
展开全部
那就实例化一个Connection conn = new Connection(ConnectionText) ;
SelectCommand.Connection = conn ;
conn.Open() ;
SelectCommand.ExecuteNonQuery() ;
conn.Close() ;
或者;
Connection conn = new Connection(ConnectionText) ;
DataAdapter da= new DataAdapter() ;
DataAdapter.SelectCommand = new Command() ;
DataAdapter.SelectCommand.Connection = conn ;
DataAdapter.SelectCommand.CommandText = selecttext ;
DataSet ds = new DataSet() ;
da.Fill(ds) ;
希望对你能有所帮助。
SelectCommand.Connection = conn ;
conn.Open() ;
SelectCommand.ExecuteNonQuery() ;
conn.Close() ;
或者;
Connection conn = new Connection(ConnectionText) ;
DataAdapter da= new DataAdapter() ;
DataAdapter.SelectCommand = new Command() ;
DataAdapter.SelectCommand.Connection = conn ;
DataAdapter.SelectCommand.CommandText = selecttext ;
DataSet ds = new DataSet() ;
da.Fill(ds) ;
希望对你能有所帮助。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询