ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Populate ComboBox from Business class using C# in Windows Application<p>Hi&nbsp;PSowmiya,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>I have made use of the following table Customers with the schema as follows.</p> <p><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=f18ac914-bc9b-437a-88e2-bd640ce05282.png" alt="" width="384" height="137" /></p> <p>I have already inserted few records in the table.</p> <p><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=b736972b-595c-4656-ab75-976e054877c7.png" alt="" width="340" height="156" /></p> <p>You can download the database table SQL by clicking the download link below.</p> <p><a href="https://www.aspsnippets.com/DownloadFile.aspx?File=Customers_Table.sql">Download SQL file</a></p> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p>Static Class to return items for populating ComboBox.</p> <pre class="brush: csharp">using System.Collections.Generic; using System.Data.SqlClient; public static class RetrieveModule { public static List&lt;string&gt; retrieveCountries() { List&lt;string&gt; countries = new List&lt;string&gt;(); SqlConnection conn = new SqlConnection(@&#34;Data Source=.;Initial Catalog=Test;Uid=sa;pwd=pass@123;&#34;); string Sql = &#34;SELECT DISTINCT Country FROM Customers;&#34;; SqlCommand cmd = new SqlCommand(Sql, conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { countries.Add(dr[&#34;Country&#34;].ToString()); } conn.Close(); return countries; } }</pre> <p>Accessing the static class in form</p> <pre class="brush: csharp">public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { List&lt;string&gt; countries = RetrieveModule.retrieveCountries(); foreach (string country in countries) { cbCountries.Items.Add(country); } } private void Submit(object sender, EventArgs e) { string message = &#34;Country: &#34; + cbCountries.Text; MessageBox.Show(message); } }</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/ATRHpYp.gif" alt="" width="149" height="125" /></span></strong></p>https://www.aspforums.net:443/Threads/188535/Populate-ComboBox-from-Business-class-using-C-in-Windows-Application/https://www.aspforums.net:443/Threads/188535/Populate-ComboBox-from-Business-class-using-C-in-Windows-Application/Tue, 30 Oct 2018 07:55:42 GMT