嗨。這是C#
在Visual Studio 2010
。我使用以下方法上傳圖像路徑。路徑已成功存儲在數據庫中並顯示上傳的圖像。然而,儘管我導航了其他記錄,但上傳的圖片仍然顯示。其他圖像不被檢索,只有上傳的圖像保持不變。保存後,我嘗試重新填充數據集,但出現錯誤:「URI爲空」。除路徑(photo_text.Text)中的圖像外,其他文本字段會成功刷新。使用從數據庫保存的路徑刷新圖像
private void uploadPhoto_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
ofd.FileName = ".jpg";
ofd.InitialDirectory = "C:\\Users\\Public\\Pictures";
ofd.Title = "Select passport photo to upload";
ofd.Filter = "Image Files (*.JPG)|*.jpg|All files (*.*)|*.*";
if (ofd.ShowDialog() == true)
{
pixx.Source = new BitmapImage(new Uri(ofd.FileName));
photo_text.Text = ofd.FileName;
}
}
第二種方法:
if (studentsDataSetstudentTableAdapter.Update(studentsDataSet.student) > 0)
{
MessageBox.Show("Your data has been saved!", "DATA STATUS", MessageBoxButton.OK, MessageBoxImage.Information);
studentsDataSetstudentTableAdapter.Fill(studentsDataSet.student);
pixx.Source = new BitmapImage(new Uri(photo_text.Text));
}