Как заполнить combobox из базы данных c
Перейти к содержимому

Как заполнить combobox из базы данных c

  • автор:

How to Fill Data in a ComboBox Using C# and MySQL Database

c#combo21

Open Microsoft Visual Studio 2015 and create a new windows form application in c#.

Step 2

C#Combo123

Do the Form just like this.

Как заполнить combobox из базы данных c

Here is a method to fill any DropDown:

dbConnection is my Class where I have methods to Open and Close connections.

You can retrieve ID using this method or as @Tom suggested in his reply.

  • Edited by OldEnthusiast Saturday, October 15, 2011 4:41 PM

r u mean you create new class for dbconnection then you call it when you need to open or close??it limits to repeat this block of code each time you want to open the connection,close

where exactly you establish this class , now i have only class Form one in my application

Dev centers
  • Windows
  • Office
  • Visual Studio
  • Microsoft Azure
  • More.
Learning resources
  • Microsoft Virtual Academy
  • Channel 9
  • MSDN Magazine
Community
  • Forums
  • Blogs
  • Codeplex
Support
Programs
  • BizSpark (for startups)
  • Microsoft Imagine (for students)
  • Newsletter
  • Privacy & cookies
  • Terms of use
  • Trademarks

logo© 2023 Microsoft

Fill ComboBox From Access Database using C# Windows Form Application

In this example, we’ll learn How to fill/populate ComboBox with Access DB Data.

The listbox will populated from database table using OleDbDataReader.

Step 1: We will use the Category table in Customers .accdb database.

Step 2: We should to put the Customers.accdb file in bin/Debug folder.

Step 3: In the next step, create a ComboBox control at design-time, you simply drag and drop a ComboBox control from Toolbox to a Form in Visual Studio.

Step 4: Write a Namespace for connectivity as in the following code snippet.

WPF привязка (обращение) значений БД к ComboBox?

Здравствуйте, обучаюсь сейчас работе с wpf, и появился вопрос как осуществить привязку значений из таблицы БД к СomboBox, или точнее как в ComboBox вернуть значения из БД. Смысл в том, чтобы значения из таблицы Education появились в виде списка в ComboBox, а потом через SelectionChanged отправить выбранный вариант в значение таблицы InformationPatient.
Пример самого окна WPF
60a77d25490f5970386611.png
Здесь добавленная к WPF база данных
60a77ff27d07f868219552.png
Это код XAML данного WPF окна

Здесь приведен код C#

  • Вопрос задан более года назад
  • 1857 просмотров
  • Facebook
  • Вконтакте
  • Twitter

Вся проблема в том, что при использовании
EduCombo.ItemsSource = DB.Educations.ToList();
в самом приложении появляется это
60a788c11e64f361839389.png

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *