Solved

OLE Grabbing Excel Strings is cutting short

Posted on 2003-12-02
11
390 Views
Last Modified: 2010-04-16
I am grabbing strings out of an excel spreadsheet and I thought all was working fine until I realized that it is pulling the first part of the text but not the full string. Anyone know how using C-sharp and an OLE connection to make sure it has grabbed all of the text out of a cell?
0
Comment
Question by:jj819430
  • 6
  • 5
11 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 9859415


Where is it breaking apart the string?  At a Space, a specific number of characters, at a specific cell width, at special characters?


0
 
LVL 7

Author Comment

by:jj819430
ID: 9859453
255 chars is the length of the string it grabs. The total is around 4000 chars.
I can't seem to find any prewritten functionality to check if it is something like EndOfFile (when dealing with a regular .txt file)
Any Ideas? I am thinking if there is a EOF or some other marker in the cell I can just concantenate until it has hit that mark. Otherwise I am not sure.

Any help is much appreciated.
0
 
LVL 7

Author Comment

by:jj819430
ID: 9859461
I also am not sure how to get another string to start reading at char 256
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9859890


That is a big problem with Crystal reports as well (any version prior to Version 9).  But that is another matter...

As for your issue, I have not encountered it before... You may need to create another variable that you pass along in your query (which will be blank 90% of the time).  This variable will contain the characters from 256 to 512 (you may even want to create a additional variables to handle up to 1,000 characters).

At any rate, as mentioned above you'll need to parse your string out into segments and then reassemble them back inside your C# code.

If you are using standard SQL commands then you command should look something like:

Select col1, col2, col3, col4, decode(length(col4)>255, true, col5=mid(col4, 256,256), col5='') from tableName where Criteria= something

0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9859919


Oh... you may also want to check the data type you are using...

I'm assuming a string, but you may want to double check to see what the OLE has specified.  It may be using some kind of data type specific to EXCEL that obly uses 254 characters.  You may be able to change a text data type to a long text or something....
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Author Comment

by:jj819430
ID: 9860195
well, I am not sure how to do what you are saying.

Basically I have the field in excel named "Buyer_Field";

it contains text of up to 4000 charachters.

I use the OLE connection and do the following select command
"Select * FROM [Buyer_Field]"

I then put this into a dataAdapter
DataSet
then try and pull it out, and it is still cutting off at 255. How do I implement what you are saying in this sense.

Do I switch the select statement around? if so, to what? The Decode is not making sense to me in how it works.

Thanks very much
0
 
LVL 7

Author Comment

by:jj819430
ID: 9860328
I thought the Decode was used for Joins between tables or cells in a database.
0
 
LVL 7

Author Comment

by:jj819430
ID: 9860402
OleDbCommand PressRelease = new OleDbCommand("SELECT * FROM [Description_Buyer]",objConn);
OleDbDataAdapter PressReleaseAdapter = new OleDbDataAdapter();
PressReleaseAdapter.SelectCommand = PressRelease;
DataSet PressReleaseDS = new DataSet();
PressReleaseAdapter.Fill(PressReleaseDS,"XLData");
PressReleaseDataGrid.DataSource = PressReleaseDS.Tables[0].DefaultView;
                  PressReleaseDataGrid.DataBind();

This is the code to bring the string out of the cell and into a DataGrid just so I can see it.
thought you might be able to see something stupid I did or some little mistake. But this is all pretty simple and straight forward.
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9860855


Decode is just like an IF statement in SQL

DECODE(Something, condition, if true, if false)


0
 
LVL 7

Author Comment

by:jj819430
ID: 9861220
I really am not sure how to implement what you are talking about. I posted a similar question in the .NET section. I will give you the points if you show me a snippet on how that works on an example. I can send you an Excel file if you want with what is giving me the problem.
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 500 total points
ID: 9862473
Using your example from above:

//obviously you'll have to change the column names from col1, col2, etc to something more meaningful

OleDbCommand PressRelease = new OleDbCommand("SELECT col1, col2, col3, Decode(Length(col3)>255,true,substr(col3,255,255),'') FROM [Description_Buyer]",objConn);



OleDbDataAdapter PressReleaseAdapter = new OleDbDataAdapter();
PressReleaseAdapter.SelectCommand = PressRelease;
DataSet PressReleaseDS = new DataSet();
PressReleaseAdapter.Fill(PressReleaseDS,"XLData");
PressReleaseDataGrid.DataSource = PressReleaseDS.Tables[0].DefaultView;
               PressReleaseDataGrid.DataBind();
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# DataGridView_RowsAdded event not firing 1 63
how to read json value 2 27
Angular - break the dataset in chunks? 7 38
C#  Radio button search for Date not DateTime 4 30
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now