开发者

storing large data in string

i am trying to store large data more than 255 characters in a string datatype but it truncates after 255. how can i achive this basically i need to pass开发者_开发知识库 this data to database


C# strings do not have any particular character limit. However the database column you are writing to may have a limit. If you are storing large amounts of data, you should use a BLOB column instead of an ordinary varchar type.


StringBuilder class

Like they said the string class is not limited, but you can do this for large strings. I feel it handles them better.

StringBuilder sb = new StringBuilder();
sb.append("Some text...");
sb.append("more text...");
sb.append("even more text!");
sb.toString(); 


Okay, it sounds like you have several different technologies involved - Excel, XML, databases etc. Try to tackle just one at a time. First read the data out of Excel, and make sure you can do that without any truncation.

Write a small console app which will read the value, then write it to the console - and its length. If that works, you know the problem isn't in Excel.

Next you can write a small console app with hardcoded input data (so you don't need to keep using interop with Excel) and write the XML from that, or whatever your next stage is.

Basically, take the one big problem ("when I read data from Excel and write it to the database it truncates long values") and split it into smaller and smaller ones until you've found what's wrong.


The string type does not limit strings to 255 characters. Your database column must be 255 characters.


I know that c# strings can hold much longer data than that. If the truncation occurs on commiting to DB, check the length constraint on ur Db field


The problem lies in the Excel part; .Character has a 255 characters limitation.

To read the complete text from a shape the following VBA syntax would do:

Worksheets("YourSheet").Shapes("Shape1").OLEFormat.Object.Text
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜