Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 35.2k

Store Qrcoder image in data base

Jul 19 2020 8:06 AM
Greeting all
I viewed many examples about generat Qrcoder and no problem with with me; a code below working correctly:
 
  1. private void GenerteSign()  
  2.     {  
  3.         string FName = txtFisrtName.Text;  
  4.         string LName = txtLastName.Text;  
  5.         string Codearray = FName + "\n" + LName;  
  6.         QRCodeGenerator qrGenerator = new QRCodeGenerator();  
  7.         QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(Codearray, QRCodeGenerator.ECCLevel.Q);  
  8.         System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();  
  9.         imgBarCode.Height = 150;  
  10.         imgBarCode.Width = 150;  
  11.   
  12.         using (Bitmap bitMap = qrCode.GetGraphic(20))  
  13.         {  
  14.             using (MemoryStream ms = new MemoryStream())  
  15.                 {  
  16.                     bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);  
  17.                     byte[] byteImage = ms.ToArray();  
  18.                     imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);  
  19.                 }//End Using Memorystream  
  20. //==Implement Qrcoder parameter to PlaceHolder Control  
  21.             PlH_Qr.Controls.Add(imgBarCode);  
  22. //==End Implement Qrcoder  
  23.         } //End Using Bitmap    
  24.     }
 So a last code we using Placholder control to catch Qrcoder value, some example use Image control (that's depends what you like).
 
My question:
How to store Plachoder value in data base, as I see placehoder just has  method (.Controls.Add).
is that possible or not.
 
 Table T-SQL Code:
 
  1. CREATE TABLE [dbo].[
    Forum_RUsers
    ] (  
  2.     [Id]              INT              IDENTITY (1, 1) NOT NULL,  
  3.     [Frm_Name]        NVARCHAR (50)    NULL,  
  4.     [Frm_LName]       NVARCHAR (50)    NULL,  
  5.     [Frm_QRSign]      VARBINARY (MAX)  NULL,  
  6.     PRIMARY KEY CLUSTERED ([Id] ASC)  
  7. );  
Secondly:
I see that example use Qrcoder implemented in (Save Button),see  refernce:
https://www.aspforums.net/Threads/208874/Generate-QR-code-Image-and-save-in-Database-using-C-and-VBnet-in-ASPNet/
Actually, that's possible to follow last example, but I need to show Qrcoder firstly and in next step let user click on save form.
 
Some suggestion in many examples said "why to use store Qrcoder in D.B , store it in image folder, that's right; But for for security level keep it in D.B".
Save Button code:
  1. protected void SendFrm(object sender, EventArgs e)  
  2.   {  
  3.       try  
  4.       {  
  5.               string CONSTRFrM = @"Data Source=(local)\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-FrmREg.mdf;Integrated Security=True";  
  6.   
  7.               using (SqlConnection con = new SqlConnection(CONSTRFrM))  
  8.               {  
  9.                   SqlCommand cmd = new SqlCommand("INSERT INTO Forum_RUsers(Frm_Name,Frm_LName,Frm_QRSign) VALUES       (@Frm_Name,@Frm_LName,@Frm_QRSign)", con);  
  10.                   cmd.CommandType = CommandType.StoredProcedure;  
  11.                   con.Open();  
  12.                   cmd.Parameters.AddWithValue("@Frm_Name", txtFisrtName.Text.Trim());  
  13.                   cmd.Parameters.AddWithValue("@Frm_LName", txtLastName.Text.Trim());  
  14.                   cmd.Parameters.AddWithValue("@Frm_QRSign","Not Implemented Yet");  
  15.                   cmd.ExecuteNonQuery();        
  16.                   lblMessage.Text = "Your Form submitted successfully";  
  17.                   lblMessage.ForeColor = System.Drawing.Color.Green;  
  18.               }  
  19.           }  
  20.       }  
  21.       catch (Exception)  
  22.       {  
  23.           lblMessage.Text = "Your record not submitted";  
  24.           lblMessage.ForeColor = System.Drawing.Color.Red;  
  25.       }  
  26.   }  
 What the solution to reuse GenerteSign() method to imlement in save code;
 thanks 
 
 

Answers (1)