Trying to fill a dataset on page load in c#

ogmike2000
ogmike2000 used Ask the Experts™
on
I'm am new to c# and I'm still having the following problem after a lot of searching:
I'm trying to fill a dataset on page load and my code looks like this:

DataSet5TableAdapters.WebAccountTableAdapter WebAccountTableAdapter1;
        WebAccountTableAdapter1 = new DataSet5TableAdapters.WebAccountTableAdapter();
        WebAccountTableAdapter1.FillByUser(DataSet5.WebAccount, Profile.UserName);

(full code is attached below"

I'm getting the following error:  
Error      1      An object reference is required for the non-static field, method, or property 'DataSet5.WebAccount.get'

I can't see what I'm missing.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet5TableAdapters.WebAccountTableAdapter WebAccountTableAdapter1;
        WebAccountTableAdapter1 = new DataSet5TableAdapters.WebAccountTableAdapter();
        WebAccountTableAdapter1.FillByUser(DataSet5.WebAccount, Profile.UserName);
      
    }

}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Where is "DataSet5.WebAccount" defined?

Author

Commented:
I believe part of the problem is the fact that I used the dataset designer in VS2010.  It's my understanding that you don't have to define and existing dataset created through the designer but as most always, i am probably wrong.  I did try:  using DataSet5TableAdapters.WebAccountTableAdapter but it didn't help.
Sr. System Analyst
Commented:
ms says:

NorthwindDataSet northwindDataSet = new NorthwindDataSet();
NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter = new NorthwindDataSetTableAdapters.CustomersTableAdapter();
customersTableAdapter.Fill(northwindDataSet.Customers);

http://msdn.microsoft.com/en-us/library/bz9tthwx(v=vs.80).aspx#Y386

so you are missing first line. try this:

DataSet5 myDataSet = new DataSet5();
DataSet5TableAdapters.WebAccountTableAdapter WebAccountTableAdapter1;
WebAccountTableAdapter1 = new DataSet5TableAdapters.WebAccountTableAdapter();
WebAccountTableAdapter1.FillByUser(myDataSet.WebAccount, Profile.UserName);

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial