Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi beginner here
So I'm using this code below to view the photo from table1/database. By typing the RefNo in the textbox the image will be called from table1/database and display in picturebox1 and I want to to save it to table2/database.

What I have tried:

C#
sqlCon.Open();

string sqlSelectQuery = "SELECT * FROM MNDBagShellTb WHERE BsRefNo = @BsRefNo";
using (SqlCommand cmd = new SqlCommand(sqlSelectQuery, sqlCon))
{
   cmd.Parameters.AddWithValue("@BsRefNo", (txtRef.Text));

   using (SqlDataReader dr = cmd.ExecuteReader())
   {
      if (dr.Read())
      {
         //stockDetails
         imageBytes = dr["SbsImage"] as byte[];
         if (imageBytes != null)
         {
            using (var stream = new MemoryStream(imageBytes))
            pbxBagImg.Image = Image.FromStream(stream);
         }
      }
   }
}
   sqlCon.Close();
Posted
Updated 28-Aug-18 4:38am
v2
Comments
Richard MacCutchan 28-Aug-18 5:18am    
Is there a question?

1 solution

So, take your "imageBytes" and save it to "table2".

Hint: there's probably code around that first saved to "table1" and you can use for "table2".

Or just use a "stored procedure" to do an SQL INSERT or UPDATE ("table1" to "table2") using the appropriate parameters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900