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 Generic List from database values using C# and VB.Net<p>Get the Data in DataTable and using for loop you can add the Row cell values to List of String.</p> <p>Please refer this code</p> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString.ToString(); List&lt;string&gt; list1 = new List&lt;string&gt;(); using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(&#34;select FirstName from Employees&#34;, con)) { SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i &lt;= dt.Rows.Count - 1; i++) { list1.Add(dt.Rows[i][&#34;FirstName&#34;].ToString()); } } }</pre> <p><span style="text-decoration: underline;">VB.Net</span></p> <pre class="brush: vb">Dim constr As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString.ToString() Dim list1 As New List(Of String)() Using con As New SqlConnection(constr) Using cmd As New SqlCommand(&#34;select FirstName from Employees&#34;, con) Dim da As New SqlDataAdapter(cmd) Dim dt As New DataTable() da.Fill(dt) For i As Integer = 0 To dt.Rows.Count - 1 list1.Add(dt.Rows(i)(&#34;FirstName&#34;).ToString()) Next End Using End Using</pre>https://www.aspforums.net:443/Threads/128550/Populate-Generic-List-from-database-values-using-C-and-VBNet/https://www.aspforums.net:443/Threads/128550/Populate-Generic-List-from-database-values-using-C-and-VBNet/Thu, 30 Oct 2014 01:53:43 GMT