Question

I am working with an excel importing tool that was created internally. The tool is supposed to read through an excel spreadsheet and import the results into a sql ce database. I have checked the database and now know after debugging the issue is coming at the point i get the value from the excel spreadsheet. My issue is with the returned results being truncated.

when I inspect my code at the comment marked "Here" the rdr.GetValue(col).ToString() has already been truncated. I am wondering if there is something I need to do differently to get the full value of the cell.

using (var cmd = _xlConn.CreateCommand())
{
    cmd.CommandText = "SELECT * FROM [" + entityType.Name + "$]";

    try
    {
        using (var rdr = cmd.ExecuteReader())
        {
            while (rdr.Read())
            {
                if (!rdr.IsDBNull(0))
                {
                    var id = Convert.ToInt32(rdr.GetValue(0));
                    var eid = Entity.InsertRecord(entityType.Name + "_" + id, entityType.ID, true);

                    map.Add(id, eid);

                    int col = 0;

                    foreach (var entityKey in _entityKeys.Where(ek => ek.EntityType_Fk == entityType.ID))
                    {
                        if (!rdr.IsDBNull(++col))
                        {
                            //-------------------------
                            //--------- HERE ----------
                            //-------------------------
                            EntityKeyData.InsertRecord(eid, entityKey.ID, rdr.GetValue(col).ToString());
                        }
                    }
                }
            }
        }
    }
}

This is my data being passed in:

<h1><span style="color:blue; margin: 10, 10, 10, 10; font-family:Arial;">You can drive
or walk on main street… Sometimes… When we allow it. Lalalalalalla lalallala lalalalal 
lalallalal allalalalalla lalallalalalalal alalallasldlal dldlaldsls dldlldl 
laldfolafjlkmn oiasfjadlfjalkfj lkajdflidja laisdjfolieanfldsn  ladllaldladsl 
aldllselasldeesl dfoaihfneal  adfajlkfmf alsiej</span></h1>

this is what is truncated:

<h1><span style="color:blue; margin: 10, 10, 10, 10; font-family:Arial;">You can drive 
or walk on main street… Sometimes… When we allow it. Lalalalalalla lalallala lalalalal 
lalallalal allalalalalla lalallalalalalal alalallasldlal dldlaldsls dldlldl laldf

I did a character count on the truncated text and it ends up being 255 Is this a common issue?

Was it helpful?

Solution

The links posted above helped me to find an answer. I found out the since I was using excel as my source, the reader will go through the first set of columns to give each column its data length. The default is 255 if its not longer. My way around this was to use my first data row as a dummy row and in the columns that were going to be very long, I added a long string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top