<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abu Ben Reaz</title>
    <description>The latest articles on DEV Community by Abu Ben Reaz (@abu_benreaz_93fc8f1c742d).</description>
    <link>https://dev.to/abu_benreaz_93fc8f1c742d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2073401%2F7f157b6d-228d-4ad6-9e24-639fa1d3e5cd.png</url>
      <title>DEV Community: Abu Ben Reaz</title>
      <link>https://dev.to/abu_benreaz_93fc8f1c742d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abu_benreaz_93fc8f1c742d"/>
    <language>en</language>
    <item>
      <title>Function/Method to get DataTable from SQL Server Database in c#</title>
      <dc:creator>Abu Ben Reaz</dc:creator>
      <pubDate>Sun, 15 Sep 2024 10:16:01 +0000</pubDate>
      <link>https://dev.to/abu_benreaz_93fc8f1c742d/functionmethod-to-get-datatable-from-sql-server-database-in-c-m6g</link>
      <guid>https://dev.to/abu_benreaz_93fc8f1c742d/functionmethod-to-get-datatable-from-sql-server-database-in-c-m6g</guid>
      <description>&lt;br&gt;
      &lt;h1&gt;Function/Method to get DataTable from SQL Server Database in c#&lt;/h1&gt;
&lt;br&gt;
      &lt;p&gt; In this sample, you pass SQL String to the function and get the result in DataTable.  You can use this function from anywhere of your application to get DataTable based on SQL String.&lt;/p&gt;
&lt;br&gt;
      &lt;span&gt;&lt;br&gt;
      &lt;p&gt; using System;&lt;/p&gt;
&lt;br&gt;
      &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;

&lt;p&gt;using System.ComponentModel;&lt;/p&gt;

&lt;p&gt;using System.Data;&lt;/p&gt;

&lt;p&gt;using System.Data.SqlClient;&lt;/p&gt;

&lt;p&gt;using System.Linq;&lt;/p&gt;

&lt;p&gt;using System.Text;&lt;/p&gt;

&lt;p&gt;using System.Threading.Tasks;&lt;/p&gt;

&lt;p&gt;using System.Windows.Forms;&lt;/p&gt;

&lt;p&gt;
namespace DBUtilities&lt;br&gt;
{&lt;br&gt;
 public class Program&lt;br&gt;
 {&lt;br&gt;
  public static void Main(string[] args) &lt;br&gt;
  {   &lt;br&gt;
   //Declare the variable&lt;br&gt;
   DataTable MyTable;&lt;br&gt;
   //Calling the function to get the result in DataTable&lt;br&gt;
   MyTable =GetTable("SELECT * FROM tblAccount”);&lt;br&gt;
  }&lt;br&gt;
  public static DataTable GetTable(string strSQL)&lt;br&gt;
  {&lt;br&gt;
   SqlConnection FillConn = new SqlConnection(YourConnetionString);&lt;br&gt;
   System.Data.DataTable UserTable = new System.Data.DataTable();&lt;br&gt;
   FillConn.Open();&lt;br&gt;
   SqlCommand sqlCommand = new SqlCommand();&lt;br&gt;
   sqlCommand.Connection = FillConn;&lt;br&gt;
   sqlCommand.CommandText = strSQL;&lt;br&gt;
   SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();&lt;br&gt;
   sqlDataAdapter.SelectCommand = sqlCommand;&lt;br&gt;
   sqlDataAdapter.Fill(UserTable);&lt;br&gt;

   return UserTable;&lt;br&gt;
  }&lt;br&gt;
 }&lt;br&gt;
}
&lt;/p&gt;

&lt;/span&gt;



</description>
      <category>csharp</category>
      <category>sqlserver</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
