0
i am doing a project that has classes, for example, a User class, where you have :code, name, password and photo and you have the user input method:
public string Inserir()
{
return "insert into Usuario(Username,Senha,Foto) values ('" + _username + "','" + _senha + "','" + _vetorImagens + "')";
}
}
}
In the registration form, I have a function that takes the chosen image in an open dialog and fills the picture box :
private void CarregaImagem()
{
try
{
this.Fd1.ShowDialog(this);
string strFn = this.Fd1.FileName;
if (string.IsNullOrEmpty(strFn))
return;
this.pbImagem.Image = Image.FromFile(strFn);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and after that by clicking the save button if there is another function that should take the information, save in the attributes of my User class and finally save in the BD:
private void btCadastrar_Click(object sender, EventArgs e)
{
if (tbCsenha.Text != tbSenha.Text)
{
MessageBox.Show("As senhas não batem ");
tbSenha.Clear();
tbCsenha.Clear();
tbSenha.Focus();
}
else
{
cUsuario cUs = new cUsuario();
MemoryStream ms = new MemoryStream();
cUs.VetorImagens = null;
pbImagem.Image.Save(ms, ImageFormat.Jpeg);
cUs.VetorImagens = ms.ToArray();
cUs.Username = tbUser.Text;
cUs.Senha = tbSenha.Text ;
if (con.Cadastro(cUs.Inserir()) == true)
{
MessageBox.Show("Cadastrado com sucesso");
tbUser.Clear();
pbImagem.Image = null;
tbSenha.Clear();
tbCsenha.Clear();
tbUser.Focus();
}
}
}
this function saves the password and the name correctly, however the photos always get the value 0x53797374656D2E427974655B5D. If anyone can help me, I’ve been racking my brain with this for a while, I’ve never manipulated images in a comic book, even with classes.
You have to necessarily save the images in the bank ? could not save only the way ?
– Igor Baesse