你好。这是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));
}