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.
Thanks

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


show some code of what you have done so far.

Edited 6 Years Ago by finito: n/a

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=208.124.179.197;Database=RTLUser;UID=sa;");
            cn.Open();
            DataSet data = new DataSet();
            string myString = "";
             myString = @"INSERT INTO germanTbl  Values('" + "collect" + "')";            SqlCommand cmd = new SqlCommand(myString, cn);

            SqlDataReader rdr = cmd.ExecuteReader();
            cn.Close();

Edited 6 Years Ago by sdhawan: n/a

http://stackoverflow.com/questions/416881/insert-picture-into-sql-server-2005-image-field-using-only-sql

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();"


P.S.

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

Edited 6 Years Ago by finito: n/a

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];
            }
            MessageBox.Show(collect.ToString());
        }

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

Edited 6 Years Ago by sdhawan: n/a

This question has already been answered. Start a new discussion instead.