Note that there are some explanatory texts on larger screens.

plurals
  1. POUse of SqlDataSource From Non-Control Situations
    primarykey
    data
    text
    <p>As part of my common utilities I used in all my line of business applications, I have this code...</p> <pre><code>using System.Web.UI.WebControls; public class Database { /// &lt;summary&gt; /// Creates a DataView object using the provided query and an SqlDataSource object. /// &lt;/summary&gt; /// &lt;param name="query"&gt;The select command to perform.&lt;/param&gt; /// &lt;returns&gt;A DataView with data results from executing the query.&lt;/returns&gt; public static DataView GetDataView(string query) { SqlDataSource ds = GetDBConnection(); ds.SelectCommand = query; DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty); return dv; } /// &lt;summary&gt; /// Creates a SqlDataSource object with initialized connection string and provider /// &lt;/summary&gt; /// &lt;returns&gt;An SqlDataSource that has been initialized.&lt;/returns&gt; public static SqlDataSource GetDBConnection() { SqlDataSource db = new SqlDataSource(); db.ConnectionString = GetDefaultConnectionString(); //retrieves connection string from .config file db.ProviderName = GetDefaultProviderName(); //retrieves provider name from .config file return db; } } </code></pre> <p>Then, in my projects, to retrieve data from databases I'll have some code like..</p> <pre><code>DataView dv=Database.GetDataView("select mycolumn from my table"); //loop through data and make use of it </code></pre> <p>I have taken some heat from people for using SqlDataSource in this manner. People don't seem to like that I'm using a Web control purely from code instead of putting it on an ASPX page. It doesn't look right to them, but they haven't been able to tell me a downside. So, is there a downside? This is my main question. Because if there's a lot of downsides, I might have to change how I'm doing many internal applications I've developed.</p> <p>My Database class even works from non-ASP.NET situations, so long as I add the System.Web assembly. I know it's a slight increase in package size, but I feel like it's worth it for the type of application I'm writing. Is there a downside to using SqlDataSource from say a WPF/Windows Forms/Console program?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload