Question Confusion in TableAdapter Configuration Wizard?

PatelNehal4u

Active member
Joined
Apr 6, 2009
Messages
25
Programming Experience
1-3
Hello Everyone,
I am new to ADO.net and still learning vb.net. Right now i am learning ado.net and use of it with windows forms. But now i am confused with one method in tableadapter configuration wizard, which is created at second last step of wizard. In wizard it create two methods :
1. Fill a datatable
Method Name : Fill()
2. Return a datatable
Method Name : GetData()

So if fill() method brings all the data from the database and populate the dataset, why we need another GetData() method. I read many books and online articles but still not cleared visually. Some one please clear me. If explanation is visually or graphically it would be better. Thanks in advance.
 
Fill and GetData both execute the same query and get the same data. The difference is that Fill will populate an existing DataTable that you pass to it while GetData will internally create its own DataTable and return that to you. If you add a DataSet to your form in the designer then you're definitely going to want to call Fill, because the DataSet already contains all the DataTables. If you create your DataTables in code then you might use either, depending on the situation.
 
So you mean that GetData() will return me always a new DataTable and if I use DataSet through code i have to use GetData() method??? But I never used that method. Fill() method simply do all the work that I need, so why this GetData() method for?? Even I add DataSet in design(.xsd) no need to call GetData() method. Fill() method fill the DataSet or DataTable which we passed.

Thanks for answering but I am still not cleared.
 
So you mean that GetData() will return me always a new DataTable
Yes.
if I use DataSet through code i have to use GetData() method?
No, the complete opposite. If you create a DataSet, whether in code or in the designer, then that DataSet already contains all your DataTables. As such you would call Fill to populate one of those tables. If you call GetData then you don't have to create a DataSet or DataTable yourself because GetData does it for you, e.g.
VB.NET:
Dim data As New MyDataSet

myTableAdapter.Fill(data.MyDataTable)
VB.NET:
Dim table As MyDataSet.MyDataTable = myTableAdapter.GetData()
 
But I never used that method. Fill() method simply do all the work that I need, so why this GetData() method for

There are hundreds/thousands of methods in the framework that you have never used.

This doesn not mean:
you will never use them
they have no use to anyone


Just wait until you write code like:

Dim dt as New XYZDataTable
myTA = Fill(dt)


You'll realise you could have written:

Dim dt as XYZDataTable = myTA.GetData()
 
Back
Top