Hi everyone i am trying to convert an object that is taken from the database and store to change it to the background of the application
con.Open();
string sqlSelectQuery = "Select * FROM Backgrounds where UserID = '" + 1 + "'";
SqlCommand cmd = new SqlCommand(sqlSelectQuery, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
byte[] yourImage = (byte[])(dr["Background"]);
MemoryStream ms = new MemoryStream(yourImage);
Image image = Image.FromStream(ms);
this.BackgroundImage = image;
}
con.Close();
Error that is shown during the conversion
CREATE TABLE [dbo].[Backgrounds] (
[UserID] INT DEFAULT ((1)) NOT NULL,
[Background] IMAGE NULL,
[Logo1] IMAGE NULL,
[Logo2] IMAGE NULL,
PRIMARY KEY CLUSTERED ([UserID] ASC)
);
What i want is the object that is taken from the database to be retrieved and use as the current background.Please let me know any mistakes that was made.
Thanks in advance.