Database backend:Postgre SQL
Database Name: MoviesDirectory
Table Name: picture
Column: img DataType:bytea
First, I store my uploaded images which may be either .jpg,.gif,.png with the following codes:
The question is that - I want to retrieve back that I have already stored the base64 string and display it with the IMAGE CONTROL on my form.
Database Name: MoviesDirectory
Table Name: picture
Column: img DataType:bytea
First, I store my uploaded images which may be either .jpg,.gif,.png with the following codes:
Code:
....
....
....
if (FileUpload1.PostedFile.ContentLength != 0)
{
byte[] b = new byte[FileUpload1.PostedFile.ContentLength];
FileUpload1.PostedFile.InputStream.Read(b, 0, b.Length);
string basestring = System.Convert.ToBase64String(b, 0, b.Length);
TextBox1.Text = basestring;
}
....
...
...
ConnStr = ConfigurationManager.ConnectionStrings["connect2MD"].ToString();
Conn = new NpgsqlConnection(ConnStr);
Conn.Open();
try
{
strSQL = new StringBuilder();
strSQL.Append("INSERT INTO picture(img) VALUES (@img)");
command = new NpgsqlCommand(strSQL.ToString(), Conn);
param = new NpgsqlParameter();
param.ParameterName = "@img";
param.Value = TextBox1.Text;
command.Parameters.Add(param);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
if (Conn.State == ConnectionState.Open)
Conn.Close();
}
...
...
..