<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:series="http://unfoldingneurons.com/"
> <channel><title>Linglom.com &#187; ASP.NET</title> <atom:link href="http://www.linglom.com/category/programming/asp-net/feed/" rel="self" type="application/rss+xml" /><link>http://www.linglom.com</link> <description>Source of IT knowledge</description> <lastBuildDate>Wed, 07 Dec 2011 14:03:35 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Accessing SQL Server on ASP.NET Web Application using ADO.NET</title><link>http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/</link> <comments>http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/#comments</comments> <pubDate>Wed, 14 Apr 2010 06:28:21 +0000</pubDate> <dc:creator>linglom</dc:creator> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[ADO.NET]]></category> <category><![CDATA[SQL Server]]></category> <guid
isPermaLink="false">http://www.linglom.com/?p=1089</guid> <description><![CDATA[ADO.NET is a set of components that can be used to access data and data services. The objects of ADO.NET that will be used in this post are: Connection: Provides a connection used to communicate with the data source. DataAdapter: A bridge used to transfer data between a Data source and a DataSet object. DataSet: [...]
Related posts:<ol><li><a
href='http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol>]]></description> <content:encoded><![CDATA[<p>ADO.NET is a set of components that can be used to access data and data services. The objects of ADO.NET that will be used in this post are:<span
id="more-1089"></span></p><ul><li><strong>Connection</strong>: Provides a connection used to communicate with the data source.</li><li><strong>DataAdapter</strong>: A bridge used to transfer data between a Data source and a DataSet object.</li><li><strong>DataSet</strong>: Stores query result from DataAdapter.</li></ul><p></p><p>On this post, you will see how to develop an ASP.NET web application that query data from SQL Server 2005 and display the result on a GridView object. I have provided both VB.NET and C# programming languages.</p><h3>Step-by-step</h3><ol><li>Create a connection string in web.config. I decide to put the connection string in web.config so that I can re-use the connection string in other web form.<div
class="wp_syntax"><div
class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&lt;</span>connectionstrings<span style="color: #006600; font-weight: bold;">&gt;</span>
		<span style="color: #006600; font-weight: bold;">&lt;</span>add name<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Northwind&quot;</span>
       connectionString<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;Data Source=BKKSQL001\INSTANCE01;
       Initial Catalog=Northwind;
       Integrated Security=True&quot;</span>
      providerName<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;System.Data.SqlClient&quot;</span><span style="color: #006600; font-weight: bold;">/&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;/</span>connectionstrings<span style="color: #006600; font-weight: bold;">&gt;</span></pre></div></div><p><strong>Attributes explanation:</strong></p><ul><li><strong>name</strong>: A connection string name.</li><li><strong>connectionString</strong>: A connection string which is used to connect to a database. On this example, it connects to Northwind database on BKKSQL001\INSTANCE01.</li><li><strong>providerName</strong>: A provider name that is used.</li></ul><p><a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/ADO.NET/1.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/ADO.NET/_1.png" width="200" height="150" alt="A Connection String" title="A Connection String"  /></a></li><li>On a Web Form, imports some namespaces which are required for working with SQL Server. System.Web.Configuration is use to read values from web.config.<div
class="wp_syntax"><div
class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'Visual Basic</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">SqlClient</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Configuration</span></pre></div></div><div
class="wp_syntax"><div
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//C#</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlClient</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.Configuration</span><span style="color: #008000;">;</span></pre></div></div></li><li>Use a GridView object to display the query result. Set the name of GridView to &#8220;<strong>gridView1</strong>&#8220;. Copy and paste the code below to <strong>Page_Load</strong> method.<div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td
class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'Visual Basic</span>
Protected <span style="color: #0600FF;">Sub</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Load</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> connStr <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> WebConfigurationManager.<span style="color: #0000FF;">ConnectionStrings</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Northwind&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ConnectionString</span>
        <span style="color: #0600FF;">Dim</span> conn <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlConnection<span style="color: #000000;">&#40;</span>connStr<span style="color: #000000;">&#41;</span>
        conn.<span style="color: #0600FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> sqlProducts <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;SELECT ProductID, ProductName, UnitPrice FROM Products&quot;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> da <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlDataAdapter<span style="color: #000000;">&#40;</span>sqlProducts, conn<span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> ds <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        da.<span style="color: #0000FF;">Fill</span><span style="color: #000000;">&#40;</span>ds, <span style="color: #808080;">&quot;Products&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        gridView1.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Products&quot;</span><span style="color: #000000;">&#41;</span>
        gridView1.<span style="color: #0000FF;">Databind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td
class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//C#</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span> connStr <span style="color: #008000;">=</span> WebConfigurationManager<span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionStrings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Northwind&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionString</span><span style="color: #008000;">;</span>
        SqlConnection conn <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlConnection<span style="color: #008000;">&#40;</span>connStr<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        conn<span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #6666cc; font-weight: bold;">string</span> sqlProducts <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SELECT ProductID, ProductName, UnitPrice FROM Products&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        SqlDataAdapter da <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlDataAdapter<span style="color: #008000;">&#40;</span>sqlProducts, conn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        DataSet ds <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataSet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        da<span style="color: #008000;">.</span><span style="color: #0000FF;">Fill</span><span style="color: #008000;">&#40;</span>ds, <span style="color: #666666;">&quot;Products&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        gridView1<span style="color: #008000;">.</span><span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> ds<span style="color: #008000;">.</span><span style="color: #0000FF;">Tables</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Products&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
        gridView1<span style="color: #008000;">.</span><span style="color: #0000FF;">DataBind</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div><p><strong>Code Explanation:</strong></p><ul><li>Line 4-6: Get a connection string value from web.config. Then, open a connection using the connection string to a SQL Server.</li><li>Line 8: Create a variable &#8220;<strong>sqlProducts</strong>&#8221; which stores SQL query from Products table.</li><li>Line 10-12: Create a SqlDataAdapter object &#8220;<strong>da</strong>&#8221; to execute the query. Then, create a DataSet object &#8220;<strong>ds</strong>&#8221; to hold the result from object &#8220;<strong>da</strong>&#8221; and set name to &#8220;<strong>Products</strong>&#8220;.</li><li>Line 14-15: Display data from object &#8220;<strong>ds</strong>&#8221; on a GridView object &#8220;<strong>gridView1</strong>&#8220;.</li></ul></li><li>Run the project. You will see the result as figure below.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/ADO.NET/2.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/ADO.NET/_2.png" width="200" height="247" alt="Northwind's Products table" title="Northwind's Products table"  /></a></li></ol><p>Related posts:<ol><li><a
href='http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</title><link>http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/</link> <comments>http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/#comments</comments> <pubDate>Fri, 02 Apr 2010 03:32:54 +0000</pubDate> <dc:creator>linglom</dc:creator> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[SQL Server]]></category> <category><![CDATA[SqlDataSource]]></category> <guid
isPermaLink="false">http://www.linglom.com/?p=1095</guid> <description><![CDATA[Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data From part 1: SELECT Data, you see how to query data from SQL Server 2005 to display on a GridView object using SqlDataSource web control. But the data is read-only, you cannot modify any data on a GridView. So now [...]
Related posts:<ol><li><a
href='http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using ADO.NET'>Accessing SQL Server on ASP.NET Web Application using ADO.NET</a> <small>ADO.NET is a set of components that can be used...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol>]]></description> <content:encoded><![CDATA[<h3>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</h3><p><span
id="more-1095"></span></p><p>From <a
href="http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/">part 1: SELECT Data</a>, you see how to query data from SQL Server 2005 to display on a GridView object using <strong>SqlDataSource</strong> web control. But the data is read-only, you cannot modify any data on a GridView. So now you will see how to modify data on the GridView which will update back on the database.</p><p></p><h3>Step-by-step</h3><p><em><strong>Note:</strong></em> This example is continue from part 1: SELECT Data.</p><ol><li>On SqlDataSource1, click on <strong>Configure Data Source</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/1.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_1.png" width="200" height="129" alt="Configure Data Source" title="Configure Data Source"  /></a></li><li>On <strong>Choose Your Data Connection</strong>, click <strong>Next</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/2.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_2.png" width="200" height="155" alt="Choose Your Data Connection" title="Choose Your Data Connection"  /></a></li><li>On <strong>Configure Select Statement</strong>, change the option from <strong>Specify columns from a table or view</strong> to <strong>Specify a custom SQL statement or stored procedure</strong>. Click <strong>Next</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/3.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_3.png" width="200" height="155" alt="Configure Select Statement" title="Configure Select Statement"  /></a></li><li>On <strong>Define Custom Statements or Stored Procedures</strong>, you see 4 tabs which are SELECT, UPDATE, INSERT and DELETE. Here you can define custom SQL statements for each SQL operations. On <strong>SELECT</strong> tab, enter the SQL statement as below:<div
class="wp_syntax"><div
class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#91;</span>ProductID<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>ProductName<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>UnitPrice<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>Products<span style="color: #66cc66;">&#93;</span></pre></div></div><p><a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/4.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_4.png" width="200" height="155" alt="Define Custom Statements or Stored Procedures" title="Define Custom Statements or Stored Procedures"  /></a></li><li>Click on <strong>UPDATE</strong> tab, enter the SQL statement below and click <strong>Next</strong>.<div
class="wp_syntax"><div
class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> Products <span style="color: #993333; font-weight: bold;">SET</span> ProductName <span style="color: #66cc66;">=</span> @ProductName<span style="color: #66cc66;">,</span> UnitPrice <span style="color: #66cc66;">=</span> @UnitPrice
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#91;</span>ProductID<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> @ProductID</pre></div></div><p><a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/5.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_5.png" width="200" height="155" alt="Update SQL Query" title="Update SQL Query"  /></a></li><li>On <strong>Test Query</strong>, Click <strong>Finish</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/6.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_6.png" width="200" height="155" alt="Test Query" title="Test Query"  /></a></li><li>On <strong>GridView1</strong>, click <strong>Edit Columns</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/7.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_7.png" width="200" height="129" alt="Edit Columns" title="Edit Columns"  /></a></li><li>On <strong>Fields</strong>, select <strong>Command Fields</strong> -> <strong>Edit, Update, Cancel</strong> on <strong>Available fields</strong> and click <strong>Add</strong>. Then, move the field <strong>Edit, Update, Cancel</strong> to the top by click on up arrow button. Next, click <strong>OK</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/8.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_8.png" width="200" height="163" alt="Add Fields on Grid View Web Control" title="Add Fields on Grid View Web Control"  /></a></li><li>On <strong>GridView1</strong>, check <strong>Enable Editing</strong> to allow edit data on the Grid View.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/9.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_9.png" width="200" height="129" alt="Enable Editing" title="Enable Editing"  /></a></li><li>Build and run the project. You see the <strong>Edit</strong> column in front of each row. Click <strong>Edit</strong> to edit the row.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/10.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_10.png" width="200" height="273" alt="Query Result" title="Query Result"  /></a></li><li>You can modify the value of product name and unit price of the row which also update back on the database, too.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/11.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-2/_11.png" width="200" height="195" alt="Edit a Row" title="Edit a Row"  /></a></li></ol><p>Related posts:<ol><li><a
href='http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using ADO.NET'>Accessing SQL Server on ASP.NET Web Application using ADO.NET</a> <small>ADO.NET is a set of components that can be used...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</title><link>http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/</link> <comments>http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/#comments</comments> <pubDate>Fri, 26 Mar 2010 04:40:26 +0000</pubDate> <dc:creator>linglom</dc:creator> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[SqlDataSource]]></category> <guid
isPermaLink="false">http://www.linglom.com/?p=1092</guid> <description><![CDATA[Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data On this post, you will see how to develop an ASP.NET web application that query data from SQL Server 2005 and display the result on a GridView object using SqlDataSource web control so you don&#8217;t have to write any code! [...]
Related posts:<ol><li><a
href='http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using ADO.NET'>Accessing SQL Server on ASP.NET Web Application using ADO.NET</a> <small>ADO.NET is a set of components that can be used...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol>]]></description> <content:encoded><![CDATA[<h3>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 1: SELECT Data</h3><p><span
id="more-1092"></span></p><p>On this post, you will see how to develop an ASP.NET web application that query data from SQL Server 2005 and display the result on a GridView object using <strong>SqlDataSource</strong> web control so you don&#8217;t have to write any code!</p><p></p><h3>Step-by-step-</h3><ol><li>Drag a <strong>SqlDataSource</strong> object from Toolbox to a Web Form.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/1.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_1.png" width="200" height="233" alt="SqlDataSource" title="SqlDataSource"  /></a></li><li>On <strong>SqlDataSource1</strong> object, click <strong>Configure Data Source</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/2.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_2.png" width="200" height="129" alt="Configure Data Source" title="Configure Data Source"  /></a></li><li>On <strong>Choose Your Data Connection</strong>, click <strong>New Connection</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/3.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_3.png" width="200" height="155" alt="Create a New Connection" title="Create a New Connection"  /></a></li><li>On <strong>Add Connection</strong>, select <strong>Data Source</strong> as <strong>Microsoft SQL Server (SqlClient)</strong>. Then, type the Server name of the SQL Server and select a database. On this example, the server is <strong>BKKSQL001\INSTANCE01</strong> and <strong>Northwind</strong> is the database.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/4.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_4.png" width="200" height="301" alt="Add Connection" title="Add Connection"  /></a></li><li>On <strong>Save the Connection String to the Application Configuration File</strong>, click <strong>Next</strong> to continue.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/5.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_5.png" width="200" height="155" alt="Save the Connection String" title="Save the Connection String"  /></a></li><li>On <strong>Configure the Select Statement</strong>, select <strong>Specify columns from table or view</strong> and select <strong>Products</strong> table. Then, check <strong>ProductID</strong>, <strong>ProductName</strong> and <strong>UnitPrice</strong> columns. Click <strong>Next</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/6.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_6.png" width="200" height="155" alt="Configure the Select Statement" title="Configure the Select Statement"  /></a></li><li>On <strong>Test Query</strong>, you can click on <strong>Test Query</strong> button to verify the query result. Then, click <strong>Finish</strong>.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/7.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_7.png" width="200" height="155" alt="Test Query" title="Test Query"  /></a></li><li>Drag a GridView object from Toolbox to the Web Form. Then, choose the Data Source to the one that you have just created.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/8.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_8.png" width="200" height="129" alt="Set Data Source for GridView Object" title="Set Data Source for GridView Object"  /></a></li><li>Build and run the project. You will see the result as the figure below.<br
/> <a
href="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/9.png" target="_blank"><img
src="http://www.linglom.com/images/Windows/Programming/ASP.NET/Access-SQLServer/SqlDataSource/Part-1/_9.png" width="200" height="247" alt="Query Result on Web Page" title="Query Result on Web Page"  /></a></li></ol><p>Related posts:<ol><li><a
href='http://www.linglom.com/2010/04/02/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-2-update-data/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data'>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web Control, Part 2: UPDATE Data</a> <small>Accessing SQL Server on ASP.NET Web Application using SqlDataSource Web...</small></li><li><a
href='http://www.linglom.com/2010/04/14/accessing-sql-server-on-asp-net-web-application-using-ado-net/' rel='bookmark' title='Accessing SQL Server on ASP.NET Web Application using ADO.NET'>Accessing SQL Server on ASP.NET Web Application using ADO.NET</a> <small>ADO.NET is a set of components that can be used...</small></li><li><a
href='http://www.linglom.com/2008/08/26/create-dynamic-rss-feed-from-ms-sql-server-using-aspnet-part-i-vbnet/' rel='bookmark' title='Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET'>Create Dynamic RSS Feed from MS SQL Server using ASP.NET, Part I: VB.NET</a> <small>Introduction Before I started, let&#8217;s get to know what RSS...</small></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.linglom.com/2010/03/26/accessing-sql-server-on-asp-net-web-application-using-sqldatasource-web-control-part-1-select-data/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic
Database Caching 6/40 queries in 0.057 seconds using disk: basic
Content Delivery Network via cdn.linglom.com/linglom

Served from: www.linglom.com @ 2012-02-10 09:53:32 -->
