我在C#中有一個客戶端應用程序,其目的是獲取圖像的位置(DataType: VarChar)
。然後,該應用程序應該調用一個Web服務,該服務又將圖像(不是位置)存儲在本地MySQL數據庫中。通過C#應用程序在MySQL中保存圖像
問題是,我意識到我能夠將所有其他數據從表單傳遞到數據庫除了圖像......任何人都可以請指出我在做什麼錯在這裏?任何幫助將不勝感激。
ps - 我知道很多人會建議我將圖像保存在文件系統中,而不是數據庫本身上....但事實是,我的數據庫不是那麼大,所以保存數據庫本身上的圖像不會是一個大問題的希望:)
這是我在MySQL表,
create table testImage(
id int not null auto_increment,
name varchar(50),
age int,
image blob,
primary key(id));
這裏是這是爲了將數據插入到表中的WebMethod
。當image
字段被註釋掉時,它可以工作。
[WebMethod]
public string sendDataToMySql(string get_name, int get_age, byte[] buffer)
{
string MyConString = "SERVER=localhost;" +
"DATABASE=test;" +
"UID=root;" +
"PASSWORD=password;";
string name_new = get_name;
int age_new = get_age;
byte[] buffer_new = buffer;
MySqlConnection connection = new MySqlConnection(MyConString);
connection.Open();
MySqlCommand command = new MySqlCommand("", connection);
command.CommandText = "insert into testdata(name, age, image) values(@name, @age, @image);";
command.Parameters.AddWithValue("@name", name_new);
command.Parameters.AddWithValue("@age", age_new);
command.Parameters.AddWithValue("@image", buffer_new);
command.ExecuteNonQuery();
connection.Close();
return "Task Performed!";
}
Blob存儲,讓我仔細檢查,還你怎麼生成的字節數據..需要看到你這樣做是爲了確保您生成的byte []正確 – MethodMan 2011-12-13 20:12:36
代碼圖像存儲爲BLOB ... – BurninatorDor 2011-12-13 20:13:18