当前位置:编程学习 > C#/ASP.NET >>

c# 文本框显示 MemoryStream 流 然后以字符串形式保存到数据库

答案:using System;   using System.IO;   using System.Text;   class MemStream   {   static void Main()   {   int count;   byte[] byteArray;   char[] charArray;   UnicodeEncoding uniEncoding = new UnicodeEncoding();   // Create the data to write to the stream.   byte[] firstString = uniEncoding.GetBytes(   "Invalid file path characters are: ");   byte[] secondString = uniEncoding.GetBytes(   Path.InvalidPathChars);   using(MemoryStream memStream = new MemoryStream(100))   {   // Write the first string to the stream.   memStream.Write(firstString, 0 , firstString.Length);   // Write the second string to the stream, byte by byte.   count = 0;   while(count < secondString.Length)   {   memStream.WriteByte(secondString[count++]);   }   // Write the stream properties to the console.   Console.WriteLine(   "Capacity = {0}, Length = {1}, Position = {2}\n",   memStream.Capacity.ToString(),   memStream.Length.ToString(),   memStream.Position.ToString());   // Set the position to the beginning of the stream.   memStream.Seek(0, SeekOrigin.Begin);   // Read the first 20 bytes from the stream.   byteArray = new byte[memStream.Length];   count = memStream.Read(byteArray, 0, 20);   // Read the remaining bytes, byte by byte.   while(count < memStream.Length)   {   byteArray[count++] =   Convert.ToByte(memStream.ReadByte());   }   // Decode the byte array into a char array   // and write it to the console.   charArray = new char[uniEncoding.GetCharCount(   byteArray, 0, count)];   uniEncoding.GetDecoder().GetChars(   byteArray, 0, count, charArray, 0);   Console.WriteLine(charArray);   }   }   }
其他:是要代码吗?
还是求思路?这个很简单啊 textBox.text=memorystream.readtoend().tostring();
查询串= "insert into [tableName] ([指定字段名])values('"+textBox.text+"')";

以上是手敲的,自己输一下吧,不能直接复制的。

上一个:vs2008太易做图了!求高人教训!!
下一个:c#串口程序调试时显示输入字符串格式不正确

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,