Try the following code in which disconnected architecture is used.
Public DataSet GetData()
{
String connectionstring = "your connection string";
using (SqlConnection connection = new SqlConnection(connectionstring))
{
if (connection.State == ConnectionState.Closed)
connection.Open();
SqlCommand command = new SqlCommand("Select * from tablename where colName = value", connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
if(connection.State == ConnectionState.Open)
connection.Close();
return ds;
}
}
if the solutions is helful to you then pls accept the solution