locked
COMBOBOX TEXT TO SELECT RECORD RRS feed

  • Question

  • Good morning firstly forgive as I have no code as struggling to find the place to begin.. So far I have reciewed some excellent help on here to write my first app.

    Essentially I have linked my app to a MS Access DB rather than SQL as this seemed to be the easiest method to load to a tablet for use, and in fairness does work. I have everything working record updating etc

    My datagrid view changes nicely when I use navigator arrows and postions all records back to text boxes combos as it should.

    Im trying rather than using the navigator to use a combobox or text box to slelect the record that is displayed.. everything I have found so far relates to sql and a fair amount of coding. Is there a simple method that is visually selectable rather than intense coding

    Saturday, August 29, 2020 12:23 PM

All replies

  • Hi dubiousp,

    Thank you for posting here.

    If you don't want to write too much database connection code and SQL statements, you can use Entity Framework. The native Entity Framework is not suitable for Access, but some people have made adaptations for this.

    EntityFrameworkCore.Jet

    1. Install the nuget package:  EntityFrameworkCore.Jet

    2. Create your model.

        class MyContext : DbContext
        {
            public DbSet<User> Users { get; set; }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder.UseJet(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\test\Database1.accdb;");
            }
    
            protected override void OnModelCreating(ModelBuilder modelBuilder)
            {
            }
        }
        [Table("Table1")]
        public class User
        {
            public int ID { get; set; }
            public string UserName { get; set; }
        }

    3. Use your model.

         using (MyContext context = new MyContext())
         {
              List<User> users = context.Users.ToList();
              dataGrid.ItemsSource = users;
         }

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 31, 2020 1:57 AM
  • If you want to use Entity Framework Core for MS-Access as Timon recommended I have a simple reverse engineering tool for automating the process found here.

    Which generates a scaffold command which you paste into the Package Manager console e.g.

    Scaffold-DbContext "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\OED\Dotnetland\ScaffoldDbContextHelper\AccessScaffoldDbContextHelper\bin\Debug\NorthWind.accdb" -Provider EntityFrameworkCore.Jet -OutputDir Models  -Context NorthWindContext  -v -f  -project NorthWind.Data -startupproject NorthWind.Data -ContextDir Contexts -t "Categories","Customers","CustomersContactTitle","Employees","Orders","Products","Suppliers","SuppliersContactTitle"


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, August 31, 2020 4:29 PM
  • Hi,

    Has your issue been resolved?

    If so, please click on the "Mark as answer" option of the reply that solved your question, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 4, 2020 8:45 AM