注册 登录
编程论坛 ASP.NET技术论坛

DATAGRID错误

想你的天空 发布于 2007-03-26 16:38, 467 次点击

public partial class datasetDataGrid : System.Web.UI.Page
{

protected System.Web.UI.WebControls.DataGrid dgrdTest;

protected void Page_Load(object sender, EventArgs e)
{
datagrid_load(sender, e);
}

protected void datagrid_load(object sender, EventArgs e)
{
string strConn = "server=localhost;uid=sa;password=987654321;database=testDB";
SqlConnection conn = new SqlConnection(strConn);
string strSql = "select * from test";
SqlCommand myCommand = new SqlCommand(strSql, conn);
conn.Open();

SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = myCommand;

DataSet myDs = new DataSet();
adapter.Fill(myDs, "Test");
conn.Close();

dgrdTest.DataSource = myDs.Tables[0].DefaultView;
dgrdTest.DataBind();
}

}
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

1 回复
#2
bygg2007-03-26 17:27
加个try..catch..就明白了
1