新手,所以在网上找些程序来试,出现错误
报错:
“ASP.printbower2_aspx.MyDataGrid_Page(object, System.Web.UI.WebControls.DataGridPageChangedEventArgs)”是一个“方法”,这在给定的上下文中无效源错误: 行 60: void BindGrid()
行 61: {
行 62: MyDataGrid_Page.DataSource = CreateDataSource();
行 63: MyDataGrid_Page.DataBind();
行 64: ShowStats();
他的CreateDataSource是这样写的:
ICollection CreateDataSource()
{
string strConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("local.mdb") + ";";
string strSQL = "SELECT * FROM MOBILE_CALL_TICKET_ZRY";
OleDbConnection MyConnection = new OleDbConnection(strConnection);
OleDbDataAdapter MyDataSetCommand = new OleDbDataAdapter(strSQL, MyConnection);
DataSet ds = new DataSet();
MyDataSetCommand.Fill(ds, "admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
我不明白为什么在上下文中无效,请大家指教。补充一下,上面的CreateDataSource()是我改过的,他用的是SQL,我要用Access,可能是我改错吧,但我不知道错在哪,他原来的程序是这样的
ICollection CreateDataSource()
{
/*
读取数据库的信息,获得DataView
*/
SQLConnection MyConnection = new SQLConnection("server=localhost;uid=sa;pwd=123456;database=aspcn");
SQLDataSetCommand MyDataSetCommand = new SQLDataSetCommand("select * from admin_enter order by Enter_Time desc",MyConnection);
DataSet ds= new DataSet();
MyDataSetCommand.FillDataSet(ds,"admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
报错:
“ASP.printbower2_aspx.MyDataGrid_Page(object, System.Web.UI.WebControls.DataGridPageChangedEventArgs)”是一个“方法”,这在给定的上下文中无效源错误: 行 60: void BindGrid()
行 61: {
行 62: MyDataGrid_Page.DataSource = CreateDataSource();
行 63: MyDataGrid_Page.DataBind();
行 64: ShowStats();
他的CreateDataSource是这样写的:
ICollection CreateDataSource()
{
string strConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("local.mdb") + ";";
string strSQL = "SELECT * FROM MOBILE_CALL_TICKET_ZRY";
OleDbConnection MyConnection = new OleDbConnection(strConnection);
OleDbDataAdapter MyDataSetCommand = new OleDbDataAdapter(strSQL, MyConnection);
DataSet ds = new DataSet();
MyDataSetCommand.Fill(ds, "admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
我不明白为什么在上下文中无效,请大家指教。补充一下,上面的CreateDataSource()是我改过的,他用的是SQL,我要用Access,可能是我改错吧,但我不知道错在哪,他原来的程序是这样的
ICollection CreateDataSource()
{
/*
读取数据库的信息,获得DataView
*/
SQLConnection MyConnection = new SQLConnection("server=localhost;uid=sa;pwd=123456;database=aspcn");
SQLDataSetCommand MyDataSetCommand = new SQLDataSetCommand("select * from admin_enter order by Enter_Time desc",MyConnection);
DataSet ds= new DataSet();
MyDataSetCommand.FillDataSet(ds,"admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
<ASP:DataGrid id="MyDataGrid" runat="server"
AllowPaging="True"
PageSize="10"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
OnPageIndexChanged="MyDataGrid_Page"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="false" >
<Columns>
<asp:BoundColumn DataField="编号 HeaderText="编号" />
<asp:BoundColumn DataField="CALLED_NBR" HeaderText="手机号码" />
<asp:BoundColumn DataField="CALLED_AREA_COD" HeaderText="被叫号码区号"
ItemStyle-HorizontalAlign="right"/>
<asp:BoundColumn DataField="CALLING_NBR" HeaderText="被叫号码"
ItemStyle-HorizontalAlign="right"/>
<asp:BoundColumn DataField="START_TIME" HeaderText="通话时间"
ItemStyle-HorizontalAlign="right"/>
<asp:BoundColumn DataField="ACCT_ITEM_TYPE" HeaderText="通话记录"
ItemStyle-HorizontalAlign="right"/>
<asp:BoundColumn DataField="CHARGE" HeaderText="通话费用"
ItemStyle-HorizontalAlign="right"/>
<asp:BoundColumn DataField="DURATION" HeaderText="持续时间"
ItemStyle-HorizontalAlign="right"/>
</Columns>
</ASP:DataGrid>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
我改了
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Web.Security " %>
<%@ Import Namespace="System.Data.OleDb" %>
------------------------------------------------
MyDataGrid_Page这是一个事件处理函数把
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();