Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / March 2005

Tip: Looking for answers? Try searching our database.

Getting column widths in an untyped dataset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erwin Pant - 18 Mar 2005 16:11 GMT
Hi,

I already sent this question however I can't seem to find it so I'm gonna
submit it again.

I'm populating .dbf and access tables into my datasets.  These files are
coming from clients so the layouts always change therefore I can't rely on
using typed datasets.  Is there a way of getting a column width working
with an untyped dataset ?  I tried using the WriteXmlSchema method which
writes to an XSD file but no column widths.  The only way that I can think
of is:
- for .dbf files:
    Open the .dbf file as a text file and extract the info from the header

- for access tables:
    Create an access object and get the column widths from the system
tables

There's got to be an easier way !!

Thanx

E
Erwin Pant - 23 Mar 2005 19:03 GMT
I seem to have found the answer to my question.  Here is a way:

-----------------
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim dc As DataColumn
    Dim dt As DataTable
    Dim dr As DataRow
    Dim strSQL As String = "SELECT * FROM Customers"

    da = New SqlDataAdapter(strSQL, NorthwindConnectionString)
    da.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Use the FillSchema method
    ds = New DataSet()
    da.FillSchema(ds, SchemaType.Source, "Customers")

    dt = New DataTable()
    dt.Columns.Add("ColumnName", GetType(System.String))
    dt.Columns.Add("DataType", GetType(System.String))
    dt.Columns.Add("AllowDBNull", GetType(System.String))
    dt.Columns.Add("DefaultValue", GetType(System.String))
    dt.Columns.Add("MaxLength", GetType(System.String))
    dt.Columns.Add("Unique", GetType(System.String))

    For Each dc In ds.Tables("Customers").Columns
        dr = dt.NewRow
        dr(0) = dc.ColumnName
        dr(1) = dc.DataType
        dr(2) = dc.AllowDBNull.ToString
        dr(3) = dc.DefaultValue.ToString
        dr(4) = dc.MaxLength.ToString
        dr(5) = dc.Unique.ToString
        dt.Rows.Add(dr)
    Next dc

    ' Bind the DataGrid to the FillSchema DataTable
    DataGrid1.DataSource = dt

    ' Bind the DataGrid to the results
    DataGrid1.DataSource = ds.Tables("Customers")
-----------------

Hope this is useful

E

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.