locked
Varbinary RRS feed

  • Question

  • User349356202 posted

    Hello,

    I have a table that contains Varbinary attributes which is causing the Jquery datatable not to load data from the table and display them.
    This is the definition of the table:

      [TakerId]       INT             IDENTITY (1, 1) NOT NULL,
        [CinTaker]      VARCHAR (10)    NOT NULL,
        [FirstName]     VARCHAR (30)    NOT NULL,
        [LastName]      VARCHAR (30)    NOT NULL,
        [Gender]        VARCHAR (10)    NOT NULL,
        [AcademicLevel] VARCHAR (50)    NOT NULL,
        [CreationDate]  DATETIME        NOT NULL,
        [ModifDate]     DATETIME        NOT NULL,
        [Accepted]      VARCHAR (10)    NOT NULL,
        [IsLogged]      INT             NOT NULL,
        [UserName]      NVARCHAR (30)   NOT NULL,
        [Password]      NVARCHAR (MAX)  NOT NULL,
        [Email]         NVARCHAR (200)  NOT NULL,
        [Address]       NVARCHAR (300)  NOT NULL,
        [Tel]           NVARCHAR (20)   NOT NULL,
        [Source]        NVARCHAR (300)  NOT NULL,
        [Image]         VARBINARY (MAX) NULL,
        [CvTaker]       VARBINARY (MAX) NULL,

    This is the method used in the controller:

    public ActionResult GetAllTakerA()
            {
                using (Part1DbEntities1 db = new Part1DbEntities1())
    
                {
                    var query = (from q in db.Taker
                                 where q.Accepted.Equals("yes")
                                 select q).ToList<Taker>();
    
                    return Json(new { data = query }, JsonRequestBehavior.AllowGet);
                }
            }

    This is code in the view:

     <script>
    
            $(document).ready(function () {
    
                $("#employeeTable").DataTable(
                    {
                        "ajax": {
                            "url": "/AdminOperations/GetAllTakerA",
                            "type": "GET",
                            "datatype": "json"
                        },
    
                        "columns": [
    
                            { "data": "TakerId" },
                            { "data": "CinTaker" }
    
                        ]
                    });
            });
    </script>

    From what i understood the Varbinary values (like this one 0x255044462D312E370D0A25...) are causing the problem.

    Is there a way i can select only 2 attributes that i want to display in the method used in the controller?
    Can i convert the value of q.Image to Base64 String URL that i can display in my datatable?

    Thank you.

    Friday, April 13, 2018 4:21 PM

Answers

  • User2053451246 posted
    (from q in db.Taker
    where q.Accepted.Equals("yes")
    select new { q.TakerId, q.CinTaker }).ToList();

    Return a generic instead of a list of <Taker>.  Add only the fields you want.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 13, 2018 4:57 PM