[英]How do I set my main application theme on a dialog box, without setting it explicitly in the XAML?
[英]How do I upload images to the SQLite database, via a dialog box, and output the image to XAML?
private void Button_Foto_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();// создаем диалоговое окно
openFile.ShowDialog();// открываем окно
string FileName = openFile.FileName;// берем полный адрес картинки
imgPath = openFile.FileName; // записываем в переменную путь к изображению
textBoxImg.Text = FileName; // выводим в текстовом поле путь к изображению (для наглядности)
//InitVariable();
if (textBoxImg.Text == "") // если не указан путь к изображению, то...
return; // прекратить выполнение
// Конвертируем изображение в байты byte[]
byte[] _imageBytes = null;
FileInfo _imgInfo = new FileInfo(imgPath); // загрузим изображение
long _numBytes = _imgInfo.Length; // вычислим длину
FileStream _fileStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read); // откроем изображение на чтение
BinaryReader _binReader = new BinaryReader(_fileStream);
_imageBytes = _binReader.ReadBytes((int)_numBytes); // изображение в байтах
imgFormat = Path.GetExtension(imgPath).Replace(".", "").ToLower(); // запишем в переменную расширение изображения в нижнем регистре, не забыв удалить (Replace) точку перед расширением
imgName = Path.GetFileName(openFile.FileName).Replace(Path.GetExtension(imgPath), ""); // запишем в переменную имя файла, не забыв удалить (Replace) расширение с точкой
// записываем информацию в базу данных
using (SQLiteConnection Connect = new SQLiteConnection("Data Source=" + dbPath + ";Version=3;"))
{
string commandText = "INSERT INTO " + db.AppStaffs + " ([image], [image_format], [image_name]) VALUES(@image, @format, @name)";
SQLiteCommand Command = new SQLiteCommand(commandText, Connect);
Command.Parameters.AddWithValue("@image", _imageBytes);
Command.Parameters.AddWithValue("@format", imgFormat);
Command.Parameters.AddWithValue("@name", imgName);
MessageBox.Show("Изображение добавлено в базу данных");
}
}
目前我正在使用代碼將圖像上傳到數據庫,但它沒有加載,它通過單擊按鈕並從對話框中選擇加載,我選擇,上傳,給出一條消息,一切都很好,是可以在不拆分為數組的情況下保存圖像,是否可以在不拆分為數組的情況下使代碼更容易? 輸出和負載都使用單個變量
您沒有使用executenonquery
方法。 所以你寫的查詢將不起作用。 完成工作后會出現該消息。
Command.ExecuteNonQuery();
使用此代碼它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.