Hi Guys,
What i am trying to do is , if suppose i have a word'horse' in a rich text box, i want to aplly image by cutting characters.To explai it little more, i want to be able to cut the word 'horse' in two parts 'hor' and 'se' and apply image to each part and store it in databse.Can anyone help me with this.

If you want to cut the word up. You can use Substring.

string varTest = "horse";
string fisrtHalf, secondHalf;
firstHalf = varTest.SubString(0,3);
secondHalf = varTest.SubString(3,2);

Of if its always Half;

string varTest = "horse";
string fisrtHalf, secondHalf;
int HalfMark = (int)(varTest.Length/2);
firstHalf = varTest.SubString(0, HalfMark);
secondHalf = varTest.SubString(HalfMark, varTest.Length - HalfMark);

I don't understand what you mean by applying image please elaborate

ok first think it might not always be half, the value of sub string could be from any position to any position.So suppose the way you said firsthalf =(0,3) this (0,3) could be any position selected by the user.So whatever part of the text he highlights in a word will become the position.
Secondly , applying image means i want to store that selected part of teh word with an image, so suppose if i pull that part again from the database it should display the image along with it.
to explain it a little more, user should be able to attach an image to the highlighted part of the word and store the haiglighted part as another word and an image should be attached to it.

ok so what specifically don't you know how to do.

show some code of what you have done so far.

this is what my approach is..

private void richTextBox1_TextChanged(object sender, EventArgs e)
            string collect = "";
            for (int i = 0; i <= richTextBox1.SelectedText.Length; i++)
                collect += collect[i].ToString();

Hmmm, can you tell me what you are doing there?

what does that piece of code supposed to do?

what i am trying to do is to get the selected part of the text in a string .

ok so what about the other part? that is only the first half

Where is you connection to the database?
where is your Update or Insert statement?

SqlDataAdapter dtadp = new SqlDataAdapter();
            DataTable dtbl = new DataTable();
            dataGridView2.MultiSelect = false;
            SqlConnection cn = new SqlConnection(@"Server=;Database=RTLUser;UID=sa;");
            DataSet data = new DataSet();
            string myString = "";
             myString = @"INSERT INTO germanTbl  Values('" + "collect" + "')";            SqlCommand cmd = new SqlCommand(myString, cn);

            SqlDataReader rdr = cmd.ExecuteReader();


Here this should help you.

You don't have to do this.

SqlDataReader rdr = cmd.ExecuteReader();

For efficiency and good practice reason I suggest you do it like this.

SqlCommand cmd = new SqlCommand(myString, cn)[B].ExecuteNonQuery();[/B]

Please Note I used ".ExecuteNonQuery();" instead of ".ExecuteReader();"


SqlDataAdapter dtadp = new SqlDataAdapter();

Why did you define that if you arn't going to use it. Maybe you used it but it doesn't show disreagrd this comment if you did.

Please Mark as solved if solved. and ask if you need clarification

kk thanks but this is not working for me first of alli am getting error at this line

collect += collect[i].ToString();

error is inder out of range

second i am not sure if my approach is correct or not .

collect += richTextBox1.Text[i];

I suggest you use this;

string fisrtHalf, secondHalf;
int HalfMark = richTextBox1.SelectedText.Length;
firstHalf = richTextBox1.SelectedText;
secondHalf = richTextBox1.Text.SubString(HalfMark, richTextBox1.Text.Length - HalfMark);

can you help me with this partof the code...

private void insert_Click(object sender, EventArgs e)
            string collect = "";
            string coll = richTextBox1.SelectedText;
            for (int i = 0; i < richTextBox1.SelectedText.Length; i++)
                collect += collect[i];

it runs file but when i select the text it show me error 'index out of range'

i got it i dont even need the loop.

yea, Please mark as solved. thanks