code hunter
Member
- Joined
- Sep 7, 2006
- Messages
- 7
- Programming Experience
- Beginner
Save & Retrieve RTF From MDF Data file
Dear friends
when i need to save image to Database i usually use such like this code
and when i want to retrive the image i use this code
now i want to use the same way to save and retrive RTF file
i did save it rightly but i couldn't retrive it and display it in rich text box can any body give me a help.
Dear friends
when i need to save image to Database i usually use such like this code
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] FileStream = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] FileStream(mImageFilePath, FileMode.Open)[/SIZE]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] img [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2]() = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2](fs.Length) {}[/SIZE][/FONT]
[SIZE=2][FONT=Times New Roman]fs.Read(img, 0, fs.Length)[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]fs.Close()[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Data.SqlClient.SqlConnection([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].MySettings.Default.imagesConnectionString)[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"INSERT INTO tab1(name,tel,img1) VALUES('"[/COLOR][/SIZE][SIZE=2] & TextBox1.Text & [/SIZE][SIZE=2][COLOR=#800000]"','"[/COLOR][/SIZE][SIZE=2] & TextBox2.Text & [/SIZE][SIZE=2][COLOR=#800000]"',@pic)"[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cmd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlCommand(str, myConnection)[/SIZE][/FONT]
[SIZE=2][COLOR=#008000][FONT=Times New Roman]' image content [/FONT][/COLOR][/SIZE]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pic [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlParameter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlParameter([/SIZE][SIZE=2][COLOR=#800000]"@pic"[/COLOR][/SIZE][SIZE=2], SqlDbType.Image)[/SIZE][/FONT]
[SIZE=2][FONT=Times New Roman]pic.Value = img[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]cmd.Parameters.Add(pic)[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]myConnection.Open()[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]cmd.ExecuteNonQuery()[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]cmd.Cancel()[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]myConnection.Close()[/FONT][/SIZE]
and when i want to retrive the image i use this code
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myByteArray() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2] = ImagesDataSet.Tables(0).Rows(1).Item([/SIZE][SIZE=2][COLOR=#800000]"img1"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myStream [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] MemoryStream = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] MemoryStream(myByteArray, [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Times New Roman]myStream.Write(myByteArray, 0, myByteArray.Length)[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] FinalImage [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Bitmap = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap(myStream)[/SIZE][/FONT]
[SIZE=2][FONT=Times New Roman]photographPictureBox.Image = FinalImage[/FONT][/SIZE]
[SIZE=2][FONT=Times New Roman]myStream.Close()[/FONT][/SIZE]
now i want to use the same way to save and retrive RTF file
i did save it rightly but i couldn't retrive it and display it in rich text box can any body give me a help.