值不能为空。参数名: dataSet ???
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
OleDbConnection sqlcon1=new OleDbConnection(ConfigurationSettings.AppSettings.Get("NWindOle"));
public DataSet ds1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
OleDbDataAdapter oadp1=new OleDbDataAdapter("select lastname,employeeid from employees",sqlcon1);
oadp1.Fill(ds1,"shankai");
DataView dv1=new DataView(ds1.Tables[0]);
Label1.Text=dv1.Count.ToString();
DataGrid2.DataSource=dv1;
DataGrid2.DataBind();
}
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid2.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid2_SortCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid2_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
DataGrid2.DataSource=ds1.Tables[0];
DataGrid2.DataBind();
}
是变量范围出问题了吗,怎么定义全局变量,怎么保存上面的Tables[0]不消失