當前位置:編程學習大全網 - 源碼下載 - C#往mysql中插入網頁富文本

C#往mysql中插入網頁富文本

樓主妳好:

這種情況保存數據的時候並不是妳想的那樣,保存起來的內容並不是string類型的,因為如果妳直接保存string的東西,肯定有很多特殊符號通不過的,妳可以把文件中的內容轉換成二進制保存到數據庫中,妳把妳的content字段創建成byte類型。代碼可以這樣寫:

public void GetStringConvertValue(string strPath) {

//strPath就是妳文件的路徑

if (File.Exists(strPath))

{

using (FileStream fs = File.Open(strPath, FileMode.Open))

{

int FileLength = Convert.ToInt32(fs.Length);

Byte[] FileByteArray = new Byte[FileLength];

fs.Read(FileByteArray, 0, FileLength);

//FileByteArray就是妳要保存的二進制內容,這裏即可以寫妳的插入語句了。

//下面的代碼妳可以看成從數據庫中讀取到FileByteArray,然後再轉換成文件ssss.txt

Stream stream = new MemoryStream(FileByteArray);

// 設置當前流的位置為流的開始

stream.Seek(0, SeekOrigin.Begin);

// 把 byte[] 寫入文件

FileStream fsss = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ssss.txt"), FileMode.Create);

BinaryWriter bw = new BinaryWriter(fsss);

bw.Write(FileByteArray);

bw.Close();

fsss.Close();

}

}

}

讀取和保存寫在壹起了,樓主自己拆分開就行了

希望對妳有幫主,望采納,謝謝:)

  • 上一篇:請教壹下,Excel宏,怎麽用代碼實現這個功能呀?
  • 下一篇:現在微信投票活動該怎麽搞,吸粉沒有以前好弄了?
  • copyright 2024編程學習大全網