locked
how to make QR code for my sql result set RRS feed

  • Question

  • User-807418713 posted

    Hello

    MSSQL QUERY IS select Name + ' - ' + Type from Table1

    It show resulset Like this

    A-001

    M-002

    J-003

    VKM-04

    Now I want to show all this in QR Code Image using jquery or javascript In Gridview How to do so using asp.net C#

    I tried this code but dont know how to pass labe1 value in text: please help

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery.classyqr.js"></script>
        
     <script>
     
    $(document).ready(function() {
     
    $('#qr').ClassyQR({
        create:true,// signals the library to create the image tag inside the container div.
     
       type:'text',// text/url/sms/email/call/locatithe text to encode in the QR. on/wifi/contact, default is TEXT
     
       text:'Welcome to jQueryScript!' // the text to encode in the QR.
     
    });
     
    });
     
    </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Label ID="L1" runat="server" Text="Read_This_Label1_TextInstead_Of_Welcome to jQueryScript!"></asp:Label>
        <div class="qrcode" id="qr">
     </div>
    
        </div>
        </form>
    </body>
    </html>
    

    Thanking You

    Sunday, December 6, 2020 5:05 PM

Answers

  • User1535942433 posted

    Hi Gopi.MCA,

    As far as I think,the extension’s lowest supported Visual Studio version is 14.0. You could return list and use JSON.stringify.

    Just like this:

     $.ajax({
                    type: "POST",
                    url: "2172757.aspx/Getnum",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        classyQRFromHF(JSON.stringify(data.d));
                    }
                });

    Code-behind:

     [System.Web.Services.WebMethod]
            public static List<qr> Getnum()
            {
               .........
                return records;
    
            }

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 9, 2020 9:41 AM

All replies

  • User1535942433 posted

    Hi Gopi.MCA,

    Accroding to your description,I have created a test.I suggest you could ajax to get your data which from database.And then pass them into the text.

    Just like this:

     <script>
            $(document).ready(function () {
                $.ajax({
                    type: "POST",
                    url: "2172757.aspx/Getnum",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        classyQRFromHF(data.d);
                    }
                }); 
            });
    
            function classyQRFromHF(value) {
                $('#qr').ClassyQR({
                    create: true,// signals the library to create the image tag inside the container div.
    
                    type: 'text',// text/url/sms/email/call/locatithe text to encode in the QR. on/wifi/contact, default is TEXT
    
                    text: value// the text to encode in the QR.
    
                });
            }
    
        </script> 
     <asp:Label ID="L1" runat="server" Text="Read_This_Label1_TextInstead_Of_Welcome to jQueryScript!"></asp:Label>
                <div class="qrcode" id="qr">
                </div>

    Code-behind:

     [System.Web.Services.WebMethod]
            public static string Getnum()
            {
                string strS, strSql;
                strS = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542"].ConnectionString;
                SqlConnection conn = new SqlConnection(strS);
                conn.Open();
                strSql = "select Id from Test";
                SqlCommand sqlCommand = new SqlCommand(strSql, conn);
                SqlDataReader objRader = sqlCommand.ExecuteReader();
                //读取数据
                List<qr> records = new List<qr>();
                if (objRader.HasRows)
                {
                    while (objRader.Read())
                    {
                        qr record = new qr();
                        record.Id = objRader["Id"].ToString();
                        records.Add(record);
                    }
                }
                conn.Close();
    
                return "{\"data\":" + JsonConvert.SerializeObject(records) + "}";
            }

    More details,you could refer to below article:

    https://www.c-sharpcorner.com/blogs/how-to-insert-and-retrieve-data-using-jquery-ajax-in-asp-net

    Best regards,

    Yijing Sun

    Monday, December 7, 2020 7:19 AM
  • User-807418713 posted

    Hello

    Please check im getting below error

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'qr' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 28:         SqlDataReader objRader = sqlCommand.ExecuteReader();
    Line 29:         
    Line 30:         List<qr> records = new List<qr>();
    Line 31:         if (objRader.HasRows)
    Line 32:         {
    Monday, December 7, 2020 10:54 AM
  • User1535942433 posted

    Hi Gopi.MCA,

    Accroding to your description,you need to create a class of qr.Just like this:

     public class qr
            {
                public string Id;
            }

    Best regards,

    Yijing Sun

    Tuesday, December 8, 2020 7:33 AM
  • User-807418713 posted

    Hello

    Again error

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'JsonConvert' does not exist in the current context

    Source Error:

    Line 47:         conn.Close();
    Line 48: 
    Line 49:         return "{\"data\":" + JsonConvert.SerializeObject(records) + "}";
    Tuesday, December 8, 2020 7:52 AM
  • User-807418713 posted

    Hi

    Any Other Method Im using old asp.net version in my website..?

    Thanking You

    Tuesday, December 8, 2020 7:53 AM
  • User1535942433 posted

    Hi Gopi.MCA,

    Accroding to your description,you could add using Newtonsoft.Json;

    If you have other problems,you could press Alt + Enter. Visual studio will resolve syntax errors intelligently.

    Best regards,

    Yijing Sun

    Tuesday, December 8, 2020 8:27 AM
  • User-807418713 posted

    Hello

    Im using older Visual Studio I think this works above VS 2015

    Tuesday, December 8, 2020 8:29 AM
  • User1535942433 posted

    Hi Gopi.MCA,

    As far as I think,the extension’s lowest supported Visual Studio version is 14.0. You could return list and use JSON.stringify.

    Just like this:

     $.ajax({
                    type: "POST",
                    url: "2172757.aspx/Getnum",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        classyQRFromHF(JSON.stringify(data.d));
                    }
                });

    Code-behind:

     [System.Web.Services.WebMethod]
            public static List<qr> Getnum()
            {
               .........
                return records;
    
            }

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 9, 2020 9:41 AM
  • User-807418713 posted

    Hello Yij sun

    Im very much thanks to you for your code

    i treid again error

    Compiler Error Message: CS0246: The type or namespace name 'JSON' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 12: using System.IO;
    Line 13: using System.Collections.Generic;
    Line 14: using JSON.stringify;

    simple my requirment is is i have gridview in that i have one column that column i want to make qr code

    so give me simple and easy solution.. this above code not works in old asp.net 2.0 c# version

    Thanking You

    Wednesday, December 9, 2020 11:07 AM
  • User1535942433 posted

    Hi Gopi.MCA,

    As far as I think,Json.Net support .net 2.0.To return a JSON object you need to serialize your response. Json.Net convert between .NET objects and JSON.

    More details,you could refer to below articles:

    https://www.aspsnippets.com/Articles/Return-JSON-data-object-from-WebMethod-PageMethod-in-ASPNet-using-C-and-VBNet.aspx

    https://stackoverflow.com/questions/20960944/passing-a-json-net-object-in-an-ajax-call

    Best regards,

    Yijing Sun

    Thursday, December 10, 2020 7:43 AM