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

  • SEARCH
  • Home
  • 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 8123077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:03:30+00:00 2026-06-06T06:03:30+00:00

I have a method in my C# class that calls a single result from

  • 0

I have a method in my C# class that calls a single result from an SQLite database. My database connection opens successfully, but after running breakpoints at different places, I noticed something odd. This is my code:

Dictionary<string, string> getResult(string id)
{
    dataConn.Open();
    SQLiteCommand comm = dataConn.CreateCommand();
    comm.CommandText = "SELECT * FROM [tableName] WHERE id='" + id + "'";
    SQLiteDataReader result = comm.ExecuteReader();
    Dictionary<string, string> resultDict = new Dictionary<string, string>();

    /*
    This doesn't work.
    while(result.Read())
    {
        resultDict.Add(result.GetName(0), result.GetString(0));
    }
    */

    result.Read();
    for (int i = 0; i < result.FieldCount; i++)
    {
        resultDict.Add(result.GetName(i), result.GetString(i));
    }
    result.Dispose();
    comm.Dispose();
    dataConn.Close();
    return resultDict;
}

I know that I can use SQLiteParameters instead of inline concatenation, but for some reason they were breaking my query.

In my first loop, if I place a breakpoint just before it starts, I can see that my query has returned a single result, exactly what I need. But, when I go into my loop, before I execute any code other than reader.Read(), VS2010 says “Enumeration yielded no results.” but they were there moments before?

So, I tried the second loop. Executing reader.Read(), and then looping through returned fields. When I do that, VS2010 throws the error “No current row selected.”.

I’m completely lost with this, I have no idea what’s wrong, because the rest of my SQLite connections for other database files work fine. I’ve tested my query in SQLite Administrator, and my query executes perfectly fine. All I’m aiming for is to end up with a dictionary where the key is the name of the field, and the value is the result of said field. Any ideas on what’s wrong? Or, is there a way I can make this code simpler, in the process of fixing it?

  • 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-06-06T06:03:31+00:00Added an answer on June 6, 2026 at 6:03 am

    Solved. For some reason, using .GetString(0) or .GetString(i) was breaking it. However, when I turned it into .GetValue(0).ToString() it worked fine. I have no idea why this is the case, it’s beyond me, but it works.

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

Sidebar

Related Questions

I'm writing a class that have a method of removing an object from other
I have a class (RInterfaceHL) that calls another class (JRIEngine) which provides native methods
i have a small doubt that how to call a method form one class
I have method in a class that I need to make sure is only
I have a class method that gets called by a view controller. I want
Fairly simple question: I have an init method on my class that has the
I'm using Java. I want to have a setter method of one class that
I have a C# class method that return a xml document not file. How
I have a private method def __pickSide(self): in a parent class that I would
I'm creating a class that will have one public method, which returns a value

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.