非常奇怪的问题,请高手指教!
代码:
using ...
namespace LYB_NEW
{
public class test_ds : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
public SqlConnection myconn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["northwind"].ToString());
public DataSet myds=new DataSet();
string str="select * from myproducts";
protected System.Web.UI.WebControls.Button Button1;
public SqlDataAdapter myda;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
this.DLbinddata();
}
}
public void DLbinddata()
{
myda=new SqlDataAdapter(str,myconn);
myda.Fill(myds,"myproducts");
this.DataGrid1.DataSource=myds.Tables["myproducts"].DefaultView;
this.DataGrid1.DataBind();
int r=myds.Tables["myproducts"].Rows.Count;
//到此都执行正确!
}
#region Web 窗体设计器生成的代码
...
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
int rows=myds.Tables[0].Rows.Count;//此行报错:0表未找到
int rows2=myds.Tables["myproducts"].Rows.Count;//此行报错:未将对象引用设置到对象的实例。
}
}
}
请高手赐教:窗体引导成功后,为何Button1_Click事件中的两句都不能成立!