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 7924645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:51:18+00:00 2026-06-03T17:51:18+00:00

To get my data(users and books) from Firebird base I am using the following

  • 0

To get my data(users and books) from Firebird base I am using the following methods:

public static Dictionary<string, Users> getUsersFromDB()
{
  Dictionary<string, Users> users_list = new Dictionary<string, Users>();
  string reqestCommand = "SELECT id, user_type, user_nick, user_pass, user_fname, user_lname, user_identify, e_mail,address, registered FROM USERS";
  string connectionString = connectionPath();
  using (FbConnection fbDB = new FbConnection(connectionString))
  {
    fbDB.Open();
    FbCommand reqest = new FbCommand(reqestCommand, fbDB);
    using (FbDataReader reader = reqest.ExecuteReader())
    {
      while (reader.Read())
      {
        string key;
        Users user = new Users();
        user.ID = reader.GetInt32(0);
        user.type = reader.GetString(1).Trim();
        key = reader.GetString(2).Trim();
        user.nick = key;
        user.password = reader.GetString(3).Trim();
        user.fName = reader.GetString(4).Trim();
        user.lName = reader.GetString(5).Trim();
        user.identify = reader.GetString(6).Trim();
        user.email = reader.GetString(7).Trim();
        user.address = reader.GetString(8).Trim();
        user.registerDate = reader.GetString(9).Trim();
        user.localOrInDb = "inDatabase";
        users_list.Add(key, user);
      }
    }
    fbDB.Close();
  }
  return users_list;
}

public static Dictionary<Guid, Books> getBooksFromDB()
{
  Dictionary<Guid, Books> books_list = new Dictionary<Guid, Books>();
  string reqestCommand = "SELECT book_id, book_title, book_author, book_genre, book_language, book_rel_date, book_page_number, book_available_amount, book_type FROM BOOKS";
  string connectionString = connectionPath();
  using (FbConnection fbDB = new FbConnection(connectionString))
  {
    fbDB.Open();
    FbCommand reqest = new FbCommand(reqestCommand, fbDB);
    using (FbDataReader reader = reqest.ExecuteReader())
    {
      while (reader.Read())
      {
        Guid key;
        Books book = new Books();
        Guid theGuid = new Guid(reader.GetString(0).Trim());
        key = book.ID = theGuid;
        book.title = reader.GetString(1).Trim();
        book.author = reader.GetString(2).Trim();
        book.genre = reader.GetString(3).Trim();
        book.language = reader.GetString(4).Trim();
        book.rel_date = reader.GetString(5).Trim();
        book.page_number = reader.GetInt32(6);
        book.amount = reader.GetInt32(7);
        book.type = reader.GetString(8).Trim();
        book.localOrInDb = "inDatabase";
        books_list.Add(key, book);
      }
    }
    fbDB.Close();
  }
  return books_list;
}

How can we see, they are almost same, so question:

Is it possible to make from them one function? Or would it be better to leave them separate?

  • 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-03T17:51:20+00:00Added an answer on June 3, 2026 at 5:51 pm

    You can pass a parameter that makes an instance of your target class from Reader:

    public static Dictionary<K,T> GetFromDb<K,T>(Func<Reader,KeyValuePair<K,T> maker) {
        var res = new Dictionary<K,T>();
        // ... your code ...
            while (reader.Read()) {
                res.Add(maker(reader));
            }
        return res;
    }
    

    Now you can call your GetFromDb like this:

    var users = GetFromDb<string,User>(reader => {
        string key;
        Users user = new Users();
        user.ID = reader.GetInt32(0);
        user.type = reader.GetString(1).Trim();
        key = reader.GetString(2).Trim();
        user.nick = key;
        user.password = reader.GetString(3).Trim();
        user.fName = reader.GetString(4).Trim();
        user.lName = reader.GetString(5).Trim();
        user.identify = reader.GetString(6).Trim();
        user.email = reader.GetString(7).Trim();
        user.address = reader.GetString(8).Trim();
        user.registerDate = reader.GetString(9).Trim();
        user.localOrInDb = "inDatabase";
        return new KeyValuePair<string,User>(key, user);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When user using the Settings' Clear Data button I get the following message: ActivityManager(201):
My Rootviewcontroller uses NSURLConnection to get data from a server, and then, based on
I need to get data from xml file <?xml version=1.0?> <xml> <User> <Agent> <id>cr4523</id>
I'm developing an android application which uses web service to get data from server,
I am able to manually get the user's data, but not programatically. Using the
How can I make this get a specific users data, Example user enters his
I have a class called Book; class Book { public string Name { get;
Suppose I have the following function, which retrieves data from a server in the
I cannot seem to get user entered data into a table and then printed.
I'd like to get some advice on how to structure the user data for

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.