dsarf f
2009-02-10 15:07:55 UTC
protected void ButtonUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
HttpPostedFile _HPFimagen = FileUpload1.PostedFile;
Byte[] _byteImagen = new Byte[_HPFimagen.ContentLength];
_HPFimagen.InputStream.Read(_byteImagen, 0, FileUpload1.PostedFile.ContentLength);
string stringConnection = "The ConnectionString";
string commandText = "Insert into Table (value)"
+ "values (@Image)";
SqlConnection connection = null;
try
{
connection = new SqlConnection(stringConnection);
connection.Open();
SqlCommand command = new SqlCommand(commandText, connection);
SqlParameter sqlParameter = new SqlParameter("@Imagen", System.Data.SqlDbType.Image);
sqlParameter.Value = _byteImagen;
command.Parameters.Add(sqlParameter);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (connection != null)
connection.Close();
}
}
}
and you Page.aspx have two controls
I replaced the connectionString and etc and this code makes sence to me. I don't know if it works, but when i go to my database, it says
protected void Button1_Click(object sender, EventArgs e)
{
string a;
string connectionString = "connection string";
SqlConnection myConnection = new SqlConnection(connectionString);
string strgCommand = "SELECT Image FROM Users WHERE uID='alsdf'";
SqlCommand myCommand = new SqlCommand(strgCommand, myConnection);
myConnection.Open();
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
a = Convert.ToString(myReader["Image"]);
}
myReader.Close();
myConnection.Close();
Image1.ImageUrl = a;
}
but it gives me a few errors, please help, I know that my conversions are bad, but I don't know how to fix it. Thank you.