- This topic explains about how to fill combobox from Microsoft sql server database in C# programming.
How to insert data into database of Microsoft SQL Server Compact
- Design the frame as shown in the figure.

How to fill combobox from Microsoft sql server database in C# – Design
Microsoft SQL Server – How to fill combobox from Microsoft sql server database in C#
- Microsoft SQL Server is a database management and analysis system for e-commerce, line-of-business, and data warehousing solutions.
- SQL Server 2012, the latest version, adds new high availability and disaster recovery solutions through AlwaysOn clusters and availability groups, xVelocity in-memory storage for extremely fast query performance
- Courtesy: Microsoft
System.Data.SqlServerCe NameSpace – How to fill combobox from Microsoft sql server database in C#
- The System.Data.SqlServerCe namespace provides programmatic access to Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) databases from a managed application.
- System.Data.SqlServerCe provides a set of classes that make available the functionality of SQL Server Compact Edition.
sqlCeCommand Class – How to fill combobox from Microsoft sql server database in C#
- Represent an SQL statement to execute against a data source.
- Syntax
|
1 2 3 4 |
// DeclarationPublicNotInheritableClass SqlCeCommand _ InheritsDbCommand; ImplementsICloneable; // UsageDim instance As SqlCeCommand |
sqlCeConnection Class – How to fill combobox from Microsoft sql server database in C#
- Represent an open connection to a SQL Server Compact data source.
- Syntax
|
1 2 3 |
// DeclarationPublicNotInheritableClass SqlCeConnection _ InheritsDbConnection; // UsageDim instance As SqlCeConnection |
sqlCeDataAdapter Class – How to fill combobox from Microsoft sql server database in C#
- Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.
- Syntax
|
1 2 3 4 |
// DeclarationPublicNotInheritableClass SqlCeDataAdapter _ InheritsDbDataAdapter; ImplementsICloneable; // UsageDim instance As SqlCeDataAdapter |
ComboBox Class – How to fill combobox from Microsoft sql server database in C#
- Represent a selection control with a drop-down list that can be shown or hidden by clicking the arrow on the control.
- Syntax
|
1 2 3 4 5 6 7 |
// Declaration [TemplatePartAttribute(Name="PART_Popup", Type=typeof(Popup))] [LocalizabilityAttribute(LocalizationCategory.ComboBox)] [TemplatePartAttribute(Name="PART_EditableTextBox", Type=typeof(TextBox))] [StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=typeof(ComboBoxItem))] public class ComboBox : Selector { } |
How to fill combobox from Microsoft sql server database in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlServerCe; namespace WindowsFormsApplication1 { public partial class Form1 : Form { SqlCeConnection sqlceCon = new SqlCeConnection(); DataTable dt = new DataTable(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Create you own database sqlceCon = new SqlCeConnection("Data Source=C:\\Program Files\\Microsoft SQL Server Compact Edition\\v3.5\\Samples\\Northwind.sdf"); sqlceCon.Open(); SqlCeDataAdapter adptrOdbc = new SqlCeDataAdapter("Select * from customers", sqlceCon); // here it fills the selected data to the datatable adptrOdbc.Fill(dt); int cnt; if ((dt.Rows.Count != 0)) { while ((cnt < dt.Rows.Count)) { cmbID.Items.Add(dt.Rows[cnt]["customer id"].ToString()); cnt = (cnt + 1); } // Selecting first item cmbID.SelectedIndex = 0; } sqlceCon.Close(); } } } |
How to fill combobox from Microsoft sql server database in C#






