1
I have a problem with how to save and take an image from the database. I would like to know a way to enter the image in the database taking into account that the number of contributor is the primary key and that after another form can use code to search for it there datagridview and put the information in a picturebox
public class BLL {
public class Imagem {
static public object loadpic(int Numero_de_contribuinte) {
DAL dal = new DAL();
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("@Numero_de_contribuinte", Numero_de_contribuinte),
};
return dal.executarScalar("select Imagem from Imagem where @Numero_de_contribuinte=@Numero_de_contribuinte", sqlParams);
}
static public DataTable Load() {
DAL dal = new DAL();
return dal.executarReader("select * from Imagem", null);
}
//Insere a imagem relativa ao numeroo de contribuinte
static public int insertImagem(byte[] img, string Numero_de_contribuinte) {
DAL dal = new DAL();
SqlParameter[] sqlParams = new SqlParameter[] {
new SqlParameter("@img", img),
new SqlParameter("@Numero_de_contribuinte", Numero_de_contribuinte)
};
return dal.executarNonQuery("INSERT into Imagem (Imagem,Numero_de_contribuinte) VALUES(@img,@Numero_de_contribuinte)", sqlParams);
}
}
private void button2_Click(object sender, EventArgs e) {
// Code Snippet
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] buff = ms.GetBuffer();
int g = BLL.Imagem.insertImagem(buff, textBox2.Text);
/* OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bit = new Bitmap(open.FileName);
pictureBox1.Image = bit;
int a = BLL.Imagem.insertImagem(bit, textBox1.Text);
}*/
}
private void button3_Click(object sender, EventArgs e) {
int o = Convert.ToInt16(textBox2.Text);
BLL.Imagem.loadpic(o);
}
Hello Pedro, do not post images of your code, put the text of your code in the question.
– Ricardo Pontual
I’m new to this,
– pedro7161
No need to wait for the next one just click on the "edit" link at the end of the question and change :)
– Ricardo Pontual
thanks ja esta I’ll only put at least the design image to get an idea :)
– pedro7161
Take a look at this link to get an idea of how to do: https://www.c-sharpcorner.com/UploadFile/deepak.sharma00/how-to-save-images-in-mysql-database-using-C-Sharp/
– Ricardo Pontual
I’ll take a look around
– pedro7161
What exactly is your doubt?
– Leandro Angelo
I would like to be able to save the image in the database . , and then be able to demonstrate the image in a picturebox by clicking on the datagridview. So far I’ve only been able to put the data that takes letters and numbers to be saved.
– pedro7161