Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Open and close connection when there is a fill()

$
0
0

Below is the code used to get data from sql into visual studio:

  

 publicstaticDataTable GetData(string selectCommand,DataTable datatable)

        {

           datatable.Clear();

           SqlConnection conn = newSqlConnection("Connection string");

           SqlCommand comm = newSqlCommand();

           SqlDataAdapter dataAdapter = newSqlDataAdapter();

            comm.CommandType = System.Data.CommandType.StoredProcedure;

            comm =newSqlCommand(selectCommand, conn);

            dataAdapter =newSqlDataAdapter(comm);

            dataAdapter.Fill(datatable);

            conn.Close();

           return datatable;

        }

this is how the connection is done would I need the conn.close() here or does the fill() method take care of that?


Debra has a question


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>