Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting information from a dataset

Status
Not open for further replies.

FOXPROG

Programmer
Jan 14, 2001
51
0
0
US
I am new to vb.net and vs 2008 so here is my problem. I have a foxpro free table that I read into a dataset then I do some manipulation of the data. What I can not figure out is how to write out to a new foxpro file with some extra fields added to it. I know I can do a "create table" but how will I know what the field lengths and data types of the original foxpro file? The problem is the file is a user supplied one so its structure is not predfined.
 
A DataSet contains a collection of DataTables.

A DataTable contains a collection of DataColumns.

Look at the properties of your DataColumns in your DataTable to get the required information.
 
Not sure how one does that in vb.net.
 
Code:
For Each DT As DataTable In YourDataSet.Tables
  For Each DC As DataColumn In DT.Columns
    MessageBox.Show("Table:  " & DT.TableName & ",  Column:  " & DC.ColumnName & " " & DC.DataType.ToString
  Next
Next
 
I also need to find the maxlength of the actual field. I can find the length of the column(i.e. "id" = 2 and "first" = 5) but I can not seem to find out how to tell what the input field length was.
 
Why do you need to find the max length? Usually before-hand, you'll have an idea of the maximum allowable length and just set your column to cover that. If you can have up to 50 characters, then set the column to 50.

But if you really need to get the actual maximum length, you can always do another loop
Code:
Dim MaxLength As Integer = 0
For Each DR As DataRow In YourDataSet.Tables("YourDataTable")
  If DR.Item("YourColumn").ToString.Length > MaxLength Then
    MaxLength = DR.Item("YourColumn").ToString.Length 
  End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top