PDA

View Full Version : DataSet issues


petela
02-22-2005, 11:21 PM
Hi,

In Visual Studio.NET, I created a typed dataset and named it yearDataSet. The schema was generated properly and the dataset was mapped to the correct table. The CodeBehind file created the namespace "bridgeport" and class "edityear" and generated this line of code:

protected bridgeport.YearDataSet yearDataSet;.

I am trying to create an editable DataGrid with Page_Load, Edit, Delete, Cancel event handlers. The problem I am having is that when I try to call up the yearDataSet in the event handlers, I do not get a compiler error, but I do get the browser error message: Value cannot be null. Parameter name: dataSet. What this is telling me is that the browser doesn't recognize that the DataSet yearDataSet has been created and instantiated. Why is the yearDataSet not available in the event handlers? Here is my partial code:

namespace bridgeport
{
public class edityear : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection DbConnection;
protected System.Data.SqlClient.SqlDataAdapter YearAdapter;
protected System.Web.UI.WebControls.DataGrid YearDataGrid;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Web.UI.HtmlControls.HtmlForm EditYearForm;
protected bridgeport.YearDataSet yearDataSet;


protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)

{
// create and open database connection
SqlConnection DbConnection = new SqlConnection("");
DbConnection.Open();

// create DataAdapter object
SqlDataAdapter YearAdapter = new SqlDataAdapter("SELECT yearid, eventyear FROM YearInfo", DbConnection);

// fill the DataAdapter
YearAdapter.Fill(yearDataSet);

// create the DataGrid source and bind
YearDataGrid.DataSource = yearDataSet;
YearDataGrid.DataBind();

// close database connection
DbConnection.Close();
}
}

Any ideas,
petela