473,770 Members | 3,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retreiving Column names from Dataset / dataAdapter

Need help finding simple way to retrieve a fields (or
columns) collection from a Dataset without filling it
first.
Nov 20 '05 #1
7 21046
You can do something like so:

Dim dt As DataTable = ds.Tables[0]
Dim colArray As String(dt.Colum ns.Count)

For counter = 0 to dt.Columns.Coun t - 1
colArray(counte r) = dt.Columns[counter].ColumnName
Next

Written on the fly, so debug may be necessary (I am more confident of my C#
right now ;->).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** *************** *************** *************** **********
Think Outside the Box!
*************** *************** *************** *************** **********
<rm******@wfubm c.edu> wrote in message
news:0b******** *************** *****@phx.gbl.. .
Need help finding simple way to retrieve a fields (or
columns) collection from a Dataset without filling it
first.

Nov 20 '05 #2
Cor
Hi Cowboy,
I did try this
Dim ds as new dataset
Dim dt As DataTable = ds.Tables(0)
Dim colArray As String(dt.Colum ns.Count)
For counter = 0 to dt.Columns.Coun t - 1
colArray(counte r) = dt.Columns(coun ter).ColumnName
Next

But there where no names.
Can you tell me what is the reason for it?

:-)))))
Need help finding simple way to retrieve a fields (or
columns) collection from a Dataset without filling it
first.


Cor
Nov 20 '05 #3
My reason is that I wish to create an sql prior to
executing the "Fill" for various tables.

The field / column names will be in a CheckListBox.

I'm 99% there by using :

Da.FillSchema(D s, SchemaType.Sour ce, "myTableNam e")
Dim X As String
X = Ds.GetXmlSchema ()

....the trouble is that the .GetXmlSchema insists on putting
<?xml version="1.0" encoding="utf-16"?> into the first
line and my XmlTextReader craps out.

the "utf-16" needs to be "utf-8" and I don't know
where / how to control it?
-----Original Message-----
Hi Cowboy,
I did try this
Dim ds as new dataset
Dim dt As DataTable = ds.Tables(0)
Dim colArray As String(dt.Colum ns.Count)
For counter = 0 to dt.Columns.Coun t - 1
colArray(counte r) = dt.Columns(coun ter).ColumnName
Next

But there where no names.
Can you tell me what is the reason for it?

:-)))))
Need help finding simple way to retrieve a fields (or
columns) collection from a Dataset without filling it
first.


Cor
.

Nov 20 '05 #4
Cor
Hi anonymous,

This I did want to hear, because with a total empty scheme you cannot do
anything,
maybe I can look tonight if I can help you or maybe the sample of Cowboy
fits you because you did fill the schema in advance?

If I see no answer I will look tonight or tomorrow.

Cor
Nov 20 '05 #5

Thanks, I seem to down to trying to get rid of the
"utf-16".

Dim x As String
pDa.FillSchema( Ds, SchemaType.Sour ce, "Department ")
x = pDs.GetXmlSchem a() ' Always "utf-16" ????

'------Save to Disk
Dim osw As System.IO.Strea mWriter
osw = New System.IO.Strea mWriter"d:\myXM L.xml")

osw.WriteLine(x )
osw.Close()
'------------------------

stop (debug) Here and fix utf-16 to utf-8......

' Read xml schema back
Dim reader As XmlTextReader
reader = New XmlTextReader(" d:\myXML.xml")

Do While (reader.Read())
... reads ok only if not utf-16

loop
....
...
..
Nov 20 '05 #6
Cor
Hi Ricm,

I still don't see the problem.

But lets take it in a solution way.

When you have an XML dataset as a seperate XML file somewhere, you dont have
to use the streamreader, but in my eyes use dataset1.readXM L(filename)

When you get it from a SQL or Access database you use OLEdb or SQL
connection, command and dataadapter.

With the dataadapter you fill the dataset

Then you have a filled dataset.

Then you can become the names with:

Dim myTable As DataTable
Dim myColumn As DataColumn
' For each table in the DataSet, print the ColumnName.
For Each myTable in dataset1.Tables
For Each myColumn in myTable.Columns
Console.WriteLi ne(myColumn.Col umnName)
Next
Next

After that you have your names, I dont know what you want to do then, but
you can connect to the datasource or do the databindings after that.

I hope it did help something, because fridayevening is not the best time for
me to provide some help, but I discovered I am the weekend most time off.

Cor
Nov 20 '05 #7

Thanks, I got your code to work by doing a Fill Schema
first.

I'm building an sql command based on the column names
(from a checkListbox). Some of the tables my app will be
using have millions of rows and can contain 50 or 60
columns, so I don't wish to FILL the dataset until AFTER
I've selected the columns and established the "WHERE"
portion of the sql command.

Since my app will use many tables, I need to collect the
column names based on which table was selected from a menu.
This enables me to add tables to the menu w/o need to know
column names for every table. (The query results are
displayed inside a DataGrid, so I'm not generating
an "Order By" in the final sql since the grid will
resequence).

Since the DataSet was empty, I was getting empty/blank
column names until I issued :

Da.FillSchema(D s, SchemaType.Sour ce, myTblName)

Now your code works and I can populate the checklistbox
items, build my sql string and Then Fill the DataSet with
only the Checked columns, saving time & memory.

Thanks a million!

Eliminates my need for the xmlReader/writer altogether.
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6631
by: Mike Gage | last post by:
I am trying to populate DataSets with results from SQL queries. Usually, to that end, the DataSet.Fill method works fine. If however the table includes a character field populated with a space, the DataSet throws an exception. I assume that the restriction is because of the DataSet's use of XML. I tried setting the XMLDataDocument's PreserveWhiteSpace property, but to no avail. The error message I receive is: The DataSet Xml...
6
5072
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
1
1807
by: yma | last post by:
Hi, I tried to use a listbox to display a column in MS Access 2000 nwind.mdb by using ole DataAdapter, Connection and dataset controls. But I got "It is already opened exclusively by another user, or you need permission to view its data." I put ole DataAdapter, Connection and dataset controls and fill in the properties of the listbox. The only code I have is OleDbDataAdapter1.Fill(DataSet11, "employees") in page_load sub. How can I...
3
1137
by: JenHu | last post by:
I have a datagrid (dgFundStatus) which displays a column. When the Transmit_Date is null, how can I show "Not transmit yet" instead of null? Thanks. Sub BindData() Dim strSql As New SqlCommand
17
3832
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset using the dataAdapter.update sub, I get an error. The problem seems to be that one of the fields was named 'desc' which is a reserved word for SQL. I've been able to work around this design flaw 'till now but it looks like the update sub can't...
16
2489
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill it with incremental values e.g. if the tables looks like this: 23 56
6
10680
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the data on the datasource. It simply gets the first name and last name of an instructor and displays it in the grid. I have two major problems.... One, it doesn't display in the column until the row is saved, (Even after calling a refresh on the...
4
1443
by: Robert Bravery | last post by:
Hi All, I'm New to VS.net. Trying to figure out this new dataset thingy. Ok so I add a dataadapter with all the correct properties for a table. Then generate the dataset. Now open the dataset and drag another table from the server explorer, set up some relations there. Set up two grids, one a s a parent one as a chgild. Fill the dataset, run the form But my child grid never gets any records. I then added another datadapter for the child...
2
1361
by: mark.norgate | last post by:
Hello I'm filling a data set in C# from an SQL database and then binding this to a repeater. I have an OnItemCreated method on this repeater and I am trying to get the value in a column called "ServiceFK". However, it appears I can only use an index rather than a column name which I am loathe to do. Can anyone help? Here's a sample of my code: protected void Page_Load(object sender, EventArgs e) {
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.