Я пытаюсь сделать следующие вещи:Невозможно добавить изображение в базу данных
- Добавить новую фотографию в базу данных (в колонке под названием «PicProfile»).
- Скопируйте путь/местоположение в текстовое поле (с именем image_path_txt). В добавлении я могу добавить запись с другими полями, кроме изображения.
Может кто-нибудь сказать мне, что я делаю неправильно?
private void button1_Click(object sender, EventArgs e)
{
byte[] imageBT = null;
FileStream fstream = new FileStream(this.image_path_txt.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBT = br.ReadBytes((int)fstream.Length);
string constring = "datasource=localhost;port=3306;username=root;password=amg135468lns";
string Query = "insert into db.newuser (FName,LName,Age,Gender,Phone_No, Mobile_No,City, Street, Street_No,Email,idNewUser,PicProfile)"+ "values('" + this.Fname_txt.Text + "','" + this.Lname_txt.Text + "','"+this.Age_txt.Text+"','"+this.Gender+"','" + this.Phone_txt.Text + "','" + this.Mobile_txt.Text + "','" + this.City_txt.Text + "','" + this.Street_txt.Text + "','" + this.StreetNo_txt.Text + "','" + this.Email_txt + "','"+this.user_no_txt.Text+"',@PicP);";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query,conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
cmdDataBase.Parameters.Add(new MySqlParameter("@PicP", imageBT));
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("Saved");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
какие ошибки вы получаете? также вам не нужен считыватель для вставки. Попробуйте 'ExecuteScalar'. –
Что вы делаете неправильно? С чего начать .... – musefan
«Пустой путь не является законным». - Это исключение. это строка taht, связанная с исключением: FileStream fstream = новый FileStream (this.image_path_txt.Text, FileMode.Open, FileAccess.Read); – Nizan