none
Modifying Width of DataCoumn RRS feed

  • Question

  • Hi,

    I have some data in a text file on which i need to do some processing and save in SQL Server.

    For that, am using the following code:

    string strConn = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" D:\File ";";
    
    OdbcConnection con;
    
    con = new OdbcConnection(strConn.Trim());
    
    con.Open();
    
    
    
    string file1 = abc.txt;
    
    OdbcDataAdapter da = new OdbcDataAdapter("Select * from [" + file1 + "]", con);
    
    DataTable dt = new DataTable();
    
    
    dt.Columns.Add("Data");
    
    da.Fill(dt);
    
    

    Now, when i check the data present in the DataTable, the data is not complete.

    For example. If each line in text file is something like:

    1111111111111111111222222222222223333333333333344444444444444555555555555

    then i only get the below data in the rows of DataTable

    111111111111111111122222222222222333333333333

    Each line of data in text file contains a large number of characters. So, if there is some default width of DataColumn, then in that case the DataTable row will contain only the partial data and not the complete one.

    I tried to look for some Width property of DataColumn but could not find one.

    Any ideas on this thing?

    Thanx,

    Sid

    Wednesday, July 7, 2010 7:06 AM

Answers

  • Hi SidGupta,

    The ODBC Text driver supports both delimited and fixed-width text files. The width of each data entry in a fixed-width text line is specified in a schema.

    Tables are limited to a maximum of 255 fields. Field names are limited to 64 characters, and field widths are limited to 32,766 characters. Records are limited to 65,000 bytes.

    And you can refer to the following article to get more information.
    http://msdn.microsoft.com/en-us/library/ms716438(VS.85).aspx

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, July 9, 2010 4:07 AM
    Moderator

All replies

  • This is a quick guess, but since the data consists numbers, it may be that this is interpreted as a numeric column.
    If it is, then the MaxLength property is ignored, see:

    "DataColumn.MaxLength Property"
    http://msdn.microsoft.com/en-us/library/system.data.datacolumn.maxlength.aspx

    What happens if you declare the columns as string: 

    dt.Columns.Add("Data", typeof(string));


    This posting is provided "AS IS" with no warranties.
    Wednesday, July 7, 2010 7:52 AM
  • Hi Michael,

    1111111111111111111222222222222223333333333333344444444444444555555555555

    was just a sample. Looks like it was misleading. The data is not exactly numbers but it is a set of Xpaths extracted from a Xml File.

    For. eg.

    x:a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/

    Something like this. But since there are large number of inner childs, so the Xpaths are very long.

    I tried to check with dt.Columns.Add("Data", typeof(string)); but that also doesnt help.

    Thanx,

    Sid

    Wednesday, July 7, 2010 8:31 AM
  • Hi SidGupta,

    The ODBC Text driver supports both delimited and fixed-width text files. The width of each data entry in a fixed-width text line is specified in a schema.

    Tables are limited to a maximum of 255 fields. Field names are limited to 64 characters, and field widths are limited to 32,766 characters. Records are limited to 65,000 bytes.

    And you can refer to the following article to get more information.
    http://msdn.microsoft.com/en-us/library/ms716438(VS.85).aspx

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, July 9, 2010 4:07 AM
    Moderator