0

I'm trying to figure out how to pull specific Entry lines from an Access Database and into a C# Program.

I'm working with a friend to make a sudoku game. We want to pull different levels of difficulty of puzzles from an access database and into a C# program.

Now my question is: Is there a way to have to program pull the specific lines from the database or would we need to load them all into the program and then have them selected from there? These would be put into a two-dimensional array.

What would be the best way to go about this?

2
  • What did you try so far? What does your database look like? Commented Apr 4, 2017 at 15:19
  • Here's one question that might help you on your way. Commented Apr 4, 2017 at 16:32

1 Answer 1

1

I'm not sure what soduku is, but I'm thinking that you need to query your Access DB. Something like this should get you started.

Class BusLogic
{
 public List<string> ListboxItems = new List<string>();
 public void PopulateListBoxItems(string userName)
 {
  string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\redgabanan\Desktop\Gabanan_Red_dbaseCon\Red_Database.accdb";
  using (OleDbConnection connection = new OleDbConnection(connString))
  {
        connection.Open();
        OleDbDataReader reader = null;
        OleDbCommand command = new OleDbCommand("SELECT * from  Users WHERE LastName='@1'", connection);            
        command.Parameters.AddWithValue("@1", userName)
        reader = command.ExecuteReader();    
        while (reader.Read())
        {
            ListboxItems.Add(reader[1].ToString()+","+reader[2].ToString());
        }    
   }
 }    
}

You could use a DataReader as well.

http://www.akadia.com/services/dotnet_data_reader.html

You definitely don't want to pull in all data from a Table; you need to somehow Query the data set.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.