2012-08-07 80 views
3

嗨,我是C#開發人員的新手。我想將文本文件保存到數據庫。我在Youtube上觀看了一些視頻。他們使用Memorystream保存圖像:將文本從文本框保存到內存?

MemoryStream ms = new MemoryStream(); 
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 

現在我嘗試從文本框中保存文本?我可以有類似的方式來做到這一點嗎? 謝謝

+0

將字符串保存到內存流?參見[SO問題] [1] [1]:http://stackoverflow.com/questions/8047064/convert-string-to-system-io-stream – Josh 2012-08-07 20:32:00

回答

3

試試這個:

MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(myTextBox.Text)) 
+0

是它的工作表示感謝。順便說一句,你知道你把這段文字從記憶流傳送到文本框嗎? – 2012-08-07 20:44:56

+0

看看這個問題:http://stackoverflow.com/questions/78181/how-do-you-get-a-string-from-a-memorystream – 2012-08-07 20:49:22

0

是的,可以。

嘗試類似這樣的東西。

MemoryStream ms = new MemoryStream(); 
ms.Write(System.Text.Encoding.UTF8.GetBytes(textBox1.Text), 0, textBox1.Length); 
+0

與textBox1.Length得到錯誤?? – 2012-08-07 20:45:23

相關問題