hi all,
I want to save content of RichTextBox (image, text etc.) to in binary or image field in SQL Server, but I couldn't...
Please help me, thank you
How to save RTF file in binary or image field in SQL Server?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Ersin Miman7 pointsPosted Jun 16, 2007, 4:34 AM EDT
FileStream inFile; Byte[] binaryData; try { inFile = new FileStream("ersin miman", FileMode.Open, FileAccess.Read); binaryData = new Byte[inFile.Length]; } catch (Exception exp) { // Error creating stream or reading from it. System.Console.WriteLine("{0}", exp.Message); return; } sqlConnection1.ConnectionString = "Data Source=localhost;Initial Catalog=dbSoru;User ID=sa;Password=xxxxxx"; sqlConnection1.Open(); SqlTransaction trs = null; try { trs = sqlConnection1.BeginTransaction(); sqlCommand1.Connection = sqlConnection1; sqlCommand1.CommandText = "INSERT INTO tbT_Soru(SoruBinary) VALUES('" + binaryData + "')"; sqlCommand1.Transaction = trs; sqlCommand1.ExecuteNonQuery(); trs.Commit(); } catch (Exception e1) { if (trs != null) { trs.Rollback(); } } sqlConnection1.Close();Ersin Miman7 pointsPosted Jun 16, 2007, 5:55 AM EDT
Can I use these method to save and read to/from binary field to SQL Server?
MemoryStream ms_memStream = new MemoryStream();
BinaryWriter br_binaryWriter = new BinaryWriter(ms_memStream);
br_binaryWriter.Write("sample text");
But, I don't know how will to use it?
sqlCommand1.CommandText = "INSERT INTO tbT_Soru(SoruBinary) VALUES(" + ms_memStream.ToString() + ")"; ????????
Wim Devos42 pointsPosted Jun 16, 2007, 6:19 AM EDT
2 short replies
Wim Devos42 pointsPosted Jun 16, 2007, 3:37 AM EDT
nguyen huu tho6 pointsPosted Jun 16, 2007, 5:46 AM EDT