I've created a table Jobs in the page load. When the user clicks a button on the page then method confirm() is called. Each time this button is hit I want to add another record to my Jobs table so that it keeps increasing in size during the session:
DataSet dsJobs = new DataSet();
DataTable jobs = new DataTable("Jobs");
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
jobs.Columns.Add(new DataColumn("Name",typeof(string)));
jobs.Columns.Add(new DataColumn("Surname",typeof(string)));
}
public void confirm()
{
DataRow rowJob = dsJobs.Tables["Jobs"].Rows.Add(new object [] {"jack","london"});
dsJobs.Tables.Add(jobs);
dgJobs.DataSource = ds;
Page.DataBind();
}
When I run this however and click on the Confirm button then I get error that
Object reference not set to an instance of an object.
for line DataRow rowJob = .........etc as above
Thanks for any help you can give on this.