0
我有一個窗體。在這種形式,當我更新一個圖像時,它顯示我這條消息: 「不支持轉換。[在(如果已知)= nvarchar轉換類型,轉換爲(如果知道)=圖像類型]」..在數據庫中數據類型是圖像..轉換不受支持。 [類型轉換(如果知道)= nvarchar,類型轉換爲(如果知道)=圖像]
這是我的代碼: 請給我一個解決方案...
ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd = new SqlCeCommand("update register set name='" + textBox1.Text + "' ,address='" + textBox2.Text + "',mobile='" + textBox3.Text + "',gender='" + a + "',dob='" + textBox4.Text + "' ,photo='"+byteArrayToImage(photo_aray)+"',worktype='" + comboBox2.SelectedItem + "',workertype='" + comboBox1.SelectedItem + "',dor='" + textBox5.Text+ "' where name='" + comboBox3.SelectedItem.ToString() + "'", con);
cmd.ExecuteNonQuery();
//convert bytearray to image...
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
謝謝...它已被您的建議解決..再次感謝..但我仍然有一個問題:我部署我的應用程序和我的連接字符串是:SqlConnection con = new SqlConnection(@「Data Source =。 \ SQLEXPRESS; AttachDbFilename = C:\\ sailesh \ Desktop \ WindowsFormsApplication1 \ WindowsFormsApplication1 \ Database1.mdf; Integrated Security = True; User Instance = True「); –
但當我在部署後在另一臺PC上運行安裝程序時,向我顯示此錯誤:「嘗試爲文件C:\ Users \ vivek.nuna \ Documents \ VisualStudio2005 \ Projects \ SubsystemSyncService \ TestClient \ bin \ Debug \ aspnetdb.mdf失敗,存在同名數據庫,或指定的文件無法打開,或位於UNC共享上。「 ..請給我解決方案..非常重要 –
我沒有足夠的信息。但是,錯誤消息應該會給你你需要自己追蹤的內容。 –