More columns than I asked for in columns collection

  • Thread starter Thread starter Douglas Buchanan
  • Start date Start date
D

Douglas Buchanan

I created an untyped dataset using the tables collection editor and
the columns collection editor.

The table was the employee table from the pubs database which has the
following eight (8) fields

emp_id
fname
minit
lname
job_id
job_lvl
pub_id
hire_date

For the table collection I supplied "employee" for both the
'TableName' and the '(Name)'

For the columns collection I added the following (7) members:
Important note: I did not add eight (8)! I did not add 'pub_id'!

emp_id
fname
minit
lname
job_id
job_lvl
hire_date

However, when the datagrid is populated I get eight (8) fields!

The field 'pub_id' is shown as the last column. Is there something I
don't understand about fileds returned in a dataset? Why am I getting
more than I ask for?

Here is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(dsEmployee, "employee")
Me.DataGrid1.SetDataBinding(dsEmployee, "employee")
End Sub

1.) Why does this happen?
======================
As an additional note. If I remove addtional fields from the column
collection, they too still are shown in the datagrid. All columns not
defined show up after those defined.


(What if someone really wants a subset of rows? What do they do?)
 
I think the problem is after this Me.SqlDataAdapter1.Fill(dsEmployee,
"employee") command
dsEmployee.tables(employee) is not same table with the employee than you
created with tables collection editor
You can use dsEmployee.tables.count() to display how many tables do you have
in you dataset, I am an beginner,
so learn each other.
 
Tarakeshwar,

Your question lead me to the answer. It is the "CommandText" of the
'SqlSelectCommand1' within the "designer generated code" that is the
query that determines which colums will appear in the DataGrid.


The DataTable influence the order in which those columns appear. Any
columns that are not added to the DataTable are shown last in the
DataGrid.

Can you or anyone tell me how to limit the DataGrid to only those
columns entered into the DataTable?

--Douglas
 
Back
Top