首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

,顶着有分

2012-03-05 
在线等,顶着有分,%@PageLanguage C# AutoEventWireup true CodeFile Default.aspx.cs Inherits

在线等,顶着有分,
<%@   Page   Language= "C# "   AutoEventWireup= "true "   CodeFile= "Default.aspx.cs "   Inherits= "_Default "   %>
<%@   import   namespace= "System.Data "   %>
<%@   Import   Namespace= "System.Data.SqlClient "   %>
<script   language= "C# "   runat= "server ">
public   void   Page_Load(Object   src,EventArgs   e)   {
        string   connec   =   "user   id=sa;password=123;initial   catalog=SQLStarnew;Server=KEYJOB;Connect   TimeOut=120; ";
        SqlConnection   objConn   =   new   SqlConnection(connec);
        objConn.Open();
        string   Sqlstr   =   "select   *   from   StarName   ";
        SqlCommand   objCommand   =   new   SqlCommand(Sqlstr,   objConn);
    DataSet   ds=new   DataSet();
    objCommand.Fill(ds);

    PagedDataSource   objPds   =   new   PagedDataSource();
    objPds.DataSource   =   ds.Tables[0].DefaultView;
    objPds.AllowPaging   =   true;
    objPds.PageSize   =   2;
    int   CurPage;
    if   (Request.QueryString[ "Page "]   !=   null)
        CurPage=Convert.ToInt32(Request.QueryString[ "Page "]);
    else
        CurPage=1;

    objPds.CurrentPageIndex   =   CurPage-1;
    lblCurrentPage.Text   =   "当前页: "   +   CurPage.ToString();

    if   (!objPds.IsFirstPage)
        lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath   +   "?Page= "   +   Convert.ToString(CurPage-1);

    if   (!objPds.IsLastPage)
        lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+   "?Page= "   +   Convert.ToString(CurPage+1);

    Repeater1.DataSource=objPds;
    Repeater1.DataBind();
}
</script>
<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   id= "Head1 "   runat= "server ">
<title> Repeater控件分页的例子 </title>

</head>
<body>
<form   id= "Form1 "   method= "POST "   runat= "server ">
<div   style= "padding:5px;background-color:#dedede ">
<asp:label   ID= "lblCurrentPage "   runat= "server "> </asp:label>
    &nbsp; <asp:HyperLink   id= "lnkPrev "   runat= "server "> 上一页 </asp:HyperLink>
    <asp:HyperLink   id= "lnkNext "   runat= "server "> 下一页 </asp:HyperLink> &nbsp;
</div>
<asp:Repeater   ID= "Repeater1 "   runat= "server ">
<Itemtemplate>
<div   style= "padding:5px;background-color:#dedede ">
<%#   DataBinder.Eval(Container.DataItem,   "Title ")   %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>


</body>
</html>

错误提示
编译器错误信息:   CS0117:   “System.Data.SqlClient.SqlCommand”并不包含“Fill”的定义

源错误:

 

行   10:           SqlCommand   objCommand   =   new   SqlCommand(Sqlstr,   objConn);
行   11:       DataSet   ds=new   DataSet();
行   12:       objCommand.Fill(ds);
行   13:  
行   14:       PagedDataSource   objPds   =   new   PagedDataSource();
 

源文件:   e:\net\Default.aspx         行:   12  


[解决办法]
objCommand.Fill(ds);没有用它fill的.应该是用SqlDataAdpater
[解决办法]
SqlCommand objCommand = new SqlCommand(Sqlstr, objConn); System.Data.SqlClient.SqlDataAdapter dpat = new System.Data.SqlClient.SqlDataAdapter(objCommand); DataSet ds=new DataSet(); dpat.Fill(ds);
[解决办法]
SqlCommand objCommand = new SqlCommand(Sqlstr, objConn);
DataSet ds=new DataSet();
objCommand.Fill(ds);

——>

SqlCommand objCommand = new SqlCommand(Sqlstr, objConn);
SqlDataAdapter adapter = new SqlDataAdapter(objCommand);
DataSet ds=new DataSet();
adapter.Fill(ds);
[解决办法]
楼上正解.
[解决办法]
cpp2017动作真是快。
[解决办法]
SqlCommand 没有fill()方法
是System.Data.SqlClient.SqlDataAdapter 有fill方法
SqlCommand objCommand = new SqlCommand(Sqlstr, objConn);
改成
System.Data.SqlClient.SqlDataAdapter objAdapter = new SqlDataAdapter (Sqlstr, objConn);
[解决办法]
适配器SqlDataAdpater
[解决办法]
对 是应该用SqlDataAdpater
[解决办法]
cpp2017(慕白兄)是专业抢沙发的?
[解决办法]
关注
[解决办法]

[解决办法]
SqlCommand objCommand = new SqlCommand(Sqlstr, objConn);
DataSet ds=new DataSet();
objCommand.Fill(ds);
你的这部分代码有问题SqlCommand 没有Fill 方法

热点排行