-1
我想使用DataBindign將圖片添加到數據庫,但我不知道該怎麼做。 這是我用來加載圖像的代碼:如何使用DataBindign將圖片添加到數據庫
byte [] imgData;
private void simpleButton5_Click_1(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
picture.ImageLocation = openFileDialog1.FileName;
imgData = File.ReadAllBytes(openFileDialog1.FileName);
}
}
catch (Exception ex)
{
// Could not load the image - probably related to Windows file system permissions.
XtraMessageBox.Show("Cannot display the image.\n You may not have permission to read the file, or " +
"it may be corrupt.\n\nReported error: " + ex.Message);
}
}
數據庫和數據綁定是不同的東西。你到底想知道什麼? – 2012-07-30 00:25:44
例如,如果我想添加一個字符串,我使用這個: textbox1.DataBindings.Add(「text」,sql.ds.Tables [「E」],「NUMETU」); 如何添加圖片? – 2012-07-30 00:41:24
但是你的數據不是來自數據庫。爲什麼你需要數據綁定?只需添加一個PictureBox並設置其圖像:PictureBox.Image = Image.FromFile(openFileDialog1.FileName) – 2012-07-30 00:45:17