Problems uploading image to database

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

This is the code And I have this error in spanish,
translation must be something like ."String has not the correct format".

La cadena de entrada no tiene el formato correcto

the code is:

private void btnUpload_Click(object sender, System.EventArgs e)

{

string ContentType = File1.PostedFile.ContentType;

int Length = System.Convert.ToInt32(File1.PostedFile.InputStream.Length);

byte[] Content = new byte[Length];

File1.PostedFile.InputStream.Read(Content,0,Length);

SqlCommand Command = new SqlCommand("INSERT Into Comprobantes(idproveedor,
archivo, tipoimagen, tamañoimagen, fecha) Values(@idproveedor, @archivo,
@tipoimagen, @tamanñoimagen, @fecha)", sqlConnection1);


SqlParameter idproveedor = new SqlParameter("@idproveedor", SqlDbType.Int);

idproveedor.Value = comboproveedores.SelectedValue;

Command.Parameters.Add(idproveedor);

SqlParameter imagen = new SqlParameter("@archivo", SqlDbType.Image);

imagen.Value = Content;

Command.Parameters.Add(imagen);

SqlParameter imageTypeParameter = new SqlParameter("@tipoimagen",
SqlDbType.NVarChar);

imageTypeParameter.Value = ContentType;

Command.Parameters.Add(imageTypeParameter);


SqlParameter imageSizeParameter = new SqlParameter("@tamanñoimagen",
SqlDbType.Int);

imageSizeParameter.Value = Length;

Command.Parameters.Add(imageSizeParameter);

SqlParameter fecha = new SqlParameter("@fecha", SqlDbType.Int);

fecha.Value = DateTime.Now.ToString();

Command.Parameters.Add(fecha);

try

{

sqlConnection1.Open();

Command.ExecuteNonQuery();

lblmensaje.Text ="Ingresado Satisfactoriamente";

paneladicionar.Visible = false;

}

catch(Exception ex)

{

lblmensaje.Text = ex.Message;

}

finally

{

sqlConnection1.Close();

}





}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top