Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris King 6 posts 87 karma points
    Jul 30, 2022 @ 00:00
    Chris King
    1

    Query custom table in Umbraco DB

    I was successful in creating the DB using NPoco but am having trouble getting the data from a function in my surface controller. I am trying to return a single email based on the query. I can't find a decent example of how to do this. I am pretty new to Umbraco and primarily a front end developer so I am giving this my best shot.

    Here is my query

        public string GetEmail(string Locations)       {
    
            using (var scope = _scopeProvider.CreateScope())
            {
                var db = scope.Database;
                var record = db.Query<ContactViewModel>("SELECT Location FROM EmailList WHERE [Location] = @Locations");
    
                return null;
            }
        }
    

    I am not sure how to wrap the query in a function. No matter what I do it just seems to fail.

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Jul 30, 2022 @ 05:53
    Huw Reddick
    0

    What errors are you getting?

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Jul 30, 2022 @ 08:27
    Huw Reddick
    100

    Try changing your query to

    var record = db.Single<ContactViewModel>("SELECT Location FROM EmailList WHERE [Location] = @0", locations);
    
  • Chris King 6 posts 87 karma points
    Jul 30, 2022 @ 21:41
    Chris King
    0

    I will try that Huw, thank you!

  • Chris King 6 posts 87 karma points
    Jul 31, 2022 @ 16:57
    Chris King
    0

    Worked like a charm Huw, thank you again!

  • Chris King 6 posts 87 karma points
    Aug 02, 2022 @ 18:08
    Chris King
    0

    Huw, I do have another Question. I tried adding an attachment to the contact form using "public IFormFile Attachment { get; set; }" in my model. When it gets to the DB Query above it throws the error below. I am pretty sure it blows up on " db.Single".

    InvalidProgramException: Common Language Runtime detected an invalid program.

    Would you know any resolution to this?

Please Sign in or register to post replies

Write your reply to:

Draft