如何在循环中附加RichTextBox [英] How to append richtextbox in a loop

查看:116
本文介绍了如何在循环中附加RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家,

我正在从数据库中获取数据,并且在循环中我想附加richtextbox.rtf:

Hello experts,

i am fetching data from database and in loop i want to append the richtextbox.rtf:

String lsVal = String.Empty;
for (int i = 0; i < lobjDS.Tables[0].Rows.Count; i++)
                    {
                        Byte[] data = (Byte[])(lobjDS.Tables[0].Rows[i]["QUESTION"]);

                        lsVal += Encoding.Unicode.GetString(data);                        
                    }
                    richTextBox2.Rtf = lsVal;



此代码仅显示第一条记录.
帮助我从数据库获取所有记录到Richtextbox.

我尝试过的事情:

上面的代码我已经尝试过,但是它只记录第一条记录.



this code is showing only first record.
help me to get all the records from data base to richtextbox.

What I have tried:

above written code i have tried but it is shoing only the first record.

推荐答案

我们无法确切地告诉您该怎么做-我们没有您的数据,因此我们无法在您可以使用的相同环境下测试您的代码.
因此,取决于您.
在显示的第一行上放置一个断点,然后通过调试器运行代码.然后查看您的代码和数据,并确定应该手动执行的操作.然后,单行检查每一行,以确保您期望发生的事情确实是正确的.如果不是,那就是您遇到问题时,可以回溯(或再次运行并仔细查看)以找出原因.
抱歉,但是我们不能为您做到这一点-是时候让您学习一种新的(也是非常非常有用的)技能:调试!

但是,为什么要将RTF数据存储在字节数组(如果从数据库中获取,则存储在VARBINARY列中)呢?如果是RTF数据,则为文本,因此请使用字符串(或NVARCHAR列)并将其直接转换为string.
We can''t tell you exactly what to do - we don''t have your data, so we can''t test your code under the same circumstances as you can.
So, its going to be up to you.
Put a breakpoint on the first line you show, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn''t, that''s when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can''t do that for you - time for you to learn a new (and very, very useful) skill: debugging!

But why are you storing the RTF data in byte array (or a VARBINARY column if you get it from a DB)? It''s text if it''s RTF data, so use a string (or a NVARCHAR column) and just cast it directly to a string.


这篇关于如何在循环中附加RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆