Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:25:59+00:00 2026-05-30T18:25:59+00:00

My code : int key = 0; //get primary key of inserted row key

  • 0

My code :

int key = 0;
            //get primary key of inserted row
            key = db.Query("SELECT max(event_id) FROM event where title=" + cevent.title +  "AND description=" + cevent.description + "AND event_start=" + cevent.start  + "AND event_end=" + cevent.end);

Error message :

Cannot implicitly convert type
‘System.Collections.Generic.IEnumerable’ to ‘int’

I am using C#, WebMatrix and SQL Server. WebMatrix. If I try and run ExecuteScalar instead of Query, I get

‘WebMatrix.Data.Database’ does not contain a definition for
‘ExecuteScalar’

Does anyone know what I can do to fix my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:26:00+00:00Added an answer on May 30, 2026 at 6:26 pm

    It sounds like you want Database.QueryValue instead.

    // No need to declare it beforehand...
    int key = (int) db.QueryValue(...);
    

    And as in your previous question, you should absolutely not be embedding the query parameter values within the SQL.

    Database.QueryValue is documented as:

    Executes a SQL query that returns a single scalar value as the result.

    … which sounds exactly right to me. It would be worth browsing through the docs – they’re not very detailed, but it would at least show you what’s available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the primary key _id from the selected group using
From this code: int x = 5; int other = 10; vector<int*> v_ptr; v_ptr.push_back(&x);
My SQL table looks like this: CREATE TABLE Page ( Id int primary key,
I'm trying to get the auto incremented column of a row. The code will
I get a stack overflow error from the last line of the below code.
This works: CREATE TABLE shoutbox_shout ( shout_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
I've got a problem when retrieving the primary key value of the last inserted
Having code: int** a = new int*[2]; a[0] = new int(1); a[1] = new
Let's take the code int a, b, c; ... if ((a + b) >
If I have the code: int f(int a) { return a; } double f(double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.