 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Select statement in asp.net</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 18:27:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Featured Member: Darryn - ITKE Community Blog</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-89519</link>
		<dc:creator>Featured Member: Darryn - ITKE Community Blog</dc:creator>
		<pubDate>Thu, 17 Mar 2011 07:00:21 +0000</pubDate>
		<guid isPermaLink="false">#comment-89519</guid>
		<description><![CDATA[[...] Select statement in asp.net [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Select statement in asp.net [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mehra</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-89008</link>
		<dc:creator>mehra</dc:creator>
		<pubDate>Sat, 05 Mar 2011 12:38:11 +0000</pubDate>
		<guid isPermaLink="false">#comment-89008</guid>
		<description><![CDATA[&lt;b&gt; Ok Carlosdl  thank  you  for  feedback  from next time  I will  use Parametrized query&lt;/b&gt;]]></description>
		<content:encoded><![CDATA[<p><b> Ok Carlosdl  thank  you  for  feedback  from next time  I will  use Parametrized query</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-88982</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Fri, 04 Mar 2011 16:37:18 +0000</pubDate>
		<guid isPermaLink="false">#comment-88982</guid>
		<description><![CDATA[Thanks for shaing this MEHRA.

I have an observation about this part:

&lt;pre&gt;Select AutoId,PName,Address,Phone,City From Person Where &lt;b&gt;AutoId=&quot;+Pid+”&lt;/b&gt;&lt;/pre&gt;

Constructing queries that way is a very bad practice, as it makes your site/application vulnerable to SQL injection attacks.

You should parameterize your queries instead.]]></description>
		<content:encoded><![CDATA[<p>Thanks for shaing this MEHRA.</p>
<p>I have an observation about this part:</p>
<pre>Select AutoId,PName,Address,Phone,City From Person Where <b>AutoId="+Pid+”</b></pre>
<p>Constructing queries that way is a very bad practice, as it makes your site/application vulnerable to SQL injection attacks.</p>
<p>You should parameterize your queries instead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mehra</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-88971</link>
		<dc:creator>mehra</dc:creator>
		<pubDate>Fri, 04 Mar 2011 13:51:11 +0000</pubDate>
		<guid isPermaLink="false">#comment-88971</guid>
		<description><![CDATA[Hi, 
friends here I m going to  explain how to  use SQL statement to select data from any table  using asp.net .
I will describe that  by using three tier architecture
&lt;b&gt;
You first create a new website .and after that you just add two class library 
Suppose website Name is Demo
1.ClassLibraryDAL [Data Access Layer]
2.&lt;b&gt;ClassLibraryBAL&lt;/b&gt; [BusinessAccess Layer]

First write Code in --ClassLibraryDAL
i am  just putting here   the code&lt;pre&gt;

=====
&lt;b&gt; First Tier
using System.Data;
using System.Data.SqlClient;
namespace ClassLibraryDAL
{
    public class PersonDAL
    {
        public DataTable SelectPeron(int Pid)
        {
            DataTable tab = new DataTable();
            string Con = @&quot;Data Source=sureit44;Initial Catalog=MydataBase;Persist Security Info=True;User ID=sitdev;Password=sitdev1&quot;;
            using (SqlConnection con = new SqlConnection(Con))
            {
                string query=&quot;Select AutoId,PName,Address,Phone,City From Person Where AutoId=&quot;+Pid+&quot;&quot;;
                SqlCommand cmd = new SqlCommand(query, con);
                con.Open();
               // cmd.Parameters.AddWithValue(&quot;@AutoId&quot;, Pid);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                da.Fill(tab);
                con.Close();
            }
            return tab;
        }
    }
}
==
after that Write Code in ClassLibraryBAL
Second Tier

&lt;/pre&gt;
==
using System.Data;
using ClassLibraryDAL;
namespace ClassLibraryBAL
{
  public  class PersonBAL
    {
        public DataTable SelectPerson(int id)
        {
            PersonDAL objPersonDAL = new PersonDAL();
            return objPersonDAL.SelectPeron(id);
           
        }
    }
}
==
&lt;/b&gt; UI  Third Tier 
In the Default.aspx page of   Demo Website 

Take one Grid view ,One Textbox and Button 

Just See this Source code for refrence&lt;pre&gt;

&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
    &lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;
    Enter PersonId 
    &lt;/td&gt;
    &lt;td&gt;
    &lt;asp:TextBox runat=&quot;server&quot;  ID=&quot;txtPersonId&quot;&gt;&lt;/asp:TextBox&gt;
    &lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt; 
    &lt;td colspan=&quot;2&quot;&gt;  &lt;/td&gt;
    &lt;td&gt; 
    &lt;asp:Button ID=&quot;btnSearch&quot; Tex=&quot;SearchPrson&quot; Text=&quot;Search&quot; runat=&quot;server&quot; 
            onclick=&quot;btnSearch_Click&quot;  /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td colspan=&quot;2&quot;&gt;  &lt;/td&gt;
    &lt;td&gt; 
    &lt;asp:GridView ID=&quot;personGrid&quot; runat=&quot;server&quot; &gt;&lt;/asp:GridView&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    
    &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/b&gt; Code Bihind file of Default.aspx.cs

&lt;/pre&gt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibraryBAL;
using System.Data;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    private void BindGrid()
    {
        int personId =int.Parse(txtPersonId.Text.ToString());
        DataTable table = new DataTable();
        PersonBAL objPersonBAL = new PersonBAL();
       table= objPersonBAL.SelectPerson(personId);
       personGrid.DataSource = table;
       personGrid.DataBind();
      
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindGrid();
    }
}

&lt;b&gt; Now  What you can do just Enter  Person id  in TextBox  and Enter Click  On Search button

I have use here Person Table
friend just add reference 
in the  following  sequence  
From ClassLibraryDAL into  ClassLibraryBAL  and then  ClassLibraryBAL   into  your Default .aspx.cs

I Hope  This Really helpful for you  
if you have Any query regrading this article the please let me  know  at my  
Id -krajmehra@gmail,com&lt;/b&gt;]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
friends here I m going to  explain how to  use SQL statement to select data from any table  using asp.net .<br />
I will describe that  by using three tier architecture<br />
<b><br />
You first create a new website .and after that you just add two class library<br />
Suppose website Name is Demo<br />
1.ClassLibraryDAL [Data Access Layer]<br />
2.</b><b>ClassLibraryBAL</b> [BusinessAccess Layer]</p>
<p>First write Code in &#8211;ClassLibraryDAL<br />
i am  just putting here   the code
<pre>

=====
<b> First Tier
using System.Data;
using System.Data.SqlClient;
namespace ClassLibraryDAL
{
    public class PersonDAL
    {
        public DataTable SelectPeron(int Pid)
        {
            DataTable tab = new DataTable();
            string Con = @"Data Source=sureit44;Initial Catalog=MydataBase;Persist Security Info=True;User ID=sitdev;Password=sitdev1";
            using (SqlConnection con = new SqlConnection(Con))
            {
                string query="Select AutoId,PName,Address,Phone,City From Person Where AutoId="+Pid+"";
                SqlCommand cmd = new SqlCommand(query, con);
                con.Open();
               // cmd.Parameters.AddWithValue("@AutoId", Pid);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                da.Fill(tab);
                con.Close();
            }
            return tab;
        }
    }
}
==
after that Write Code in ClassLibraryBAL
Second Tier

</b></pre>
<p>==<br />
using System.Data;<br />
using ClassLibraryDAL;<br />
namespace ClassLibraryBAL<br />
{<br />
  public  class PersonBAL<br />
    {<br />
        public DataTable SelectPerson(int id)<br />
        {<br />
            PersonDAL objPersonDAL = new PersonDAL();<br />
            return objPersonDAL.SelectPeron(id);</p>
<p>        }<br />
    }<br />
}<br />
==<br />
 UI  Third Tier<br />
In the Default.aspx page of   Demo Website </p>
<p>Take one Grid view ,One Textbox and Button </p>
<p>Just See this Source code for refrence
<pre>

&lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
    &lt;table&gt;
    &lt;tr&gt;
    &lt;td&gt;
    Enter PersonId 
    &lt;/td&gt;
    &lt;td&gt;
    &lt;asp:TextBox runat="server"  ID="txtPersonId"&gt;&lt;/asp:TextBox&gt;
    &lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt; 
    &lt;td colspan="2"&gt;  &lt;/td&gt;
    &lt;td&gt; 
    &lt;asp:Button ID="btnSearch" Tex="SearchPrson" Text="Search" runat="server" 
            onclick="btnSearch_Click"  /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
    &lt;td colspan="2"&gt;  &lt;/td&gt;
    &lt;td&gt; 
    &lt;asp:GridView ID="personGrid" runat="server" &gt;&lt;/asp:GridView&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    
    &lt;/table&gt;
    &lt;/div&gt;
    &lt;/form&gt;
 Code Bihind file of Default.aspx.cs

</pre>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using ClassLibraryBAL;<br />
using System.Data;</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {</p>
<p>    }</p>
<p>    private void BindGrid()<br />
    {<br />
        int personId =int.Parse(txtPersonId.Text.ToString());<br />
        DataTable table = new DataTable();<br />
        PersonBAL objPersonBAL = new PersonBAL();<br />
       table= objPersonBAL.SelectPerson(personId);<br />
       personGrid.DataSource = table;<br />
       personGrid.DataBind();</p>
<p>    }<br />
    protected void btnSearch_Click(object sender, EventArgs e)<br />
    {<br />
        BindGrid();<br />
    }<br />
}</p>
<p><b> Now  What you can do just Enter  Person id  in TextBox  and Enter Click  On Search button</p>
<p>I have use here Person Table<br />
friend just add reference<br />
in the  following  sequence<br />
From ClassLibraryDAL into  ClassLibraryBAL  and then  ClassLibraryBAL   into  your Default .aspx.cs</p>
<p>I Hope  This Really helpful for you<br />
if you have Any query regrading this article the please let me  know  at my<br />
Id -krajmehra@gmail,com</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: darryn</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-79407</link>
		<dc:creator>darryn</dc:creator>
		<pubDate>Tue, 20 Jul 2010 13:55:44 +0000</pubDate>
		<guid isPermaLink="false">#comment-79407</guid>
		<description><![CDATA[Here is a good tutorial for data driven asp sites:

http://www.asp.net/data-access/tutorials

I would suggest building the data access and business logic layers in the fashion described, then use them in the web page controls.]]></description>
		<content:encoded><![CDATA[<p>Here is a good tutorial for data driven asp sites:</p>
<p><a href="http://www.asp.net/data-access/tutorials" rel="nofollow">http://www.asp.net/data-access/tutorials</a></p>
<p>I would suggest building the data access and business logic layers in the fashion described, then use them in the web page controls.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rickmartinez</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/select-statement-in-aspnet/#comment-79366</link>
		<dc:creator>rickmartinez</dc:creator>
		<pubDate>Mon, 19 Jul 2010 21:35:35 +0000</pubDate>
		<guid isPermaLink="false">#comment-79366</guid>
		<description><![CDATA[Mr. Denny is right you should use a stored procedure, but if you want to use sql inside your code then I would look into LINQ or ADO.NET there is a link sample below.

                DataContext qn = new DataContext();
                qn.CommandTimeout = 0;

                var query =
                    from source1 in qn.data(a_oStart, a_oEnd, plan)
                    on sourc1.person_num 
                    orderby source1.name
                    select new
                    {
                        col1.name,
                        col2.lastname

                    };
                foreach(var encounters in query)
                {
                 //loop through records   
                    }]]></description>
		<content:encoded><![CDATA[<p>Mr. Denny is right you should use a stored procedure, but if you want to use sql inside your code then I would look into LINQ or ADO.NET there is a link sample below.</p>
<p>                DataContext qn = new DataContext();<br />
                qn.CommandTimeout = 0;</p>
<p>                var query =<br />
                    from source1 in qn.data(a_oStart, a_oEnd, plan)<br />
                    on sourc1.person_num<br />
                    orderby source1.name<br />
                    select new<br />
                    {<br />
                        col1.name,<br />
                        col2.lastname</p>
<p>                    };<br />
                foreach(var encounters in query)<br />
                {<br />
                 //loop through records<br />
                    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/8 queries in 0.035 seconds using memcached
Object Caching 339/340 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-22 23:31:46 -->