<?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/"
	>

<channel>
	<title>www.pritambaldota.com &#187; Articles</title>
	<atom:link href="http://www.pritambaldota.com/index.php/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pritambaldota.com</link>
	<description>.Net Free Community</description>
	<lastBuildDate>Fri, 15 Apr 2011 10:11:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>SQL Server Database Triggers</title>
		<link>http://www.pritambaldota.com/index.php/sql-server-database-triggers/</link>
		<comments>http://www.pritambaldota.com/index.php/sql-server-database-triggers/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 15:32:59 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[database triggers]]></category>
		<category><![CDATA[SQL Server Database Triggers]]></category>
		<category><![CDATA[sql triggers]]></category>

		<guid isPermaLink="false">http://www.pritambaldota.com/?p=52</guid>
		<description><![CDATA[A trigger is an object contained within an SQL Server database that is used to execute a batch of SQL code whenever a specific event occurs. A trigger is “fired” whenever an INSERT, UPDATE, or DELETE SQL command is executed against a specific table. A Trigger is associated with Database Table There are three types [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>A trigger is an object contained within an SQL Server database that is used to execute a batch of SQL code whenever a specific event occurs.</li>
<li>A trigger is “fired” whenever an INSERT, UPDATE, or DELETE SQL command is executed against a specific table.</li>
<li>A Trigger is associated with Database Table</li>
</ul>
<p>There are three types of Database Triggers -</p>
<ol>
<li>INSERT TRIGGER</li>
<li>UPDATE TRIGGER</li>
<li>DELETE TRIGGER</li>
</ol>
<p><strong><span style="text-decoration: underline;">INSERT TRIGGER</span></strong></p>
<ul>
<li>Body of trigger can have any block which a Stored Procedure can have</li>
<li>Body can call SP using Exec</li>
<li>When SQL server processes this &#8220;INSERT&#8221; command, it creates a new virtual table, which contains all nine of the fields in the &#8220;INSERT&#8221; command. This table is named <strong><em>&#8220;Inserted&#8221;</em></strong>, and is passed to the <em>trig_addAuthor </em>trigger.</li>
<li>At any one time, each trigger only deals with one row.</li>
<li>So for INSERT Trigger only hold reference of <em>Inserted virtual Table</em></li>
</ul>
<p><span style="color: #0000ff;">CREATE TRIGGER trig_addAuthor<br />
ON authors<br />
FOR INSERT<br />
AS<br />
&#8211; Get the first and last name of new author<br />
DECLARE @newName VARCHAR(100)<br />
SELECT @newName = (SELECT au_fName + &#8216; &#8216; + au_lName FROM<br />
Inserted)<br />
&#8211; Print the name of the new author<br />
PRINT &#8216;New author &#8220;&#8216; + @newName + &#8216;&#8221; added.&#8217;</span></p>
<p><strong><span style="text-decoration: underline;">UPDATE TRIGGER</span></strong></p>
<ul>
<li>The &#8220;UPDATE&#8221; function is used to check whether or not the &#8220;au_fName&#8221; and &#8220;au_lName&#8221; fields have been updated by the &#8220;UPDATE&#8221; Query</li>
<li>&#8220;UPDATE&#8221; triggers have access to two virtual tables: Deleted (which contains all of the fields and values for the records before they were updated), and Inserted (which contains all of the fields and values for the records after they have been updated)</li>
<li>Update triggers can also be used to check field constraints and relationships</li>
</ul>
<p><span style="color: #0000ff;">CREATE TRIGGER trig_updateAuthor<br />
ON authors<br />
FOR UPDATE<br />
AS<br />
DECLARE @oldName VARCHAR(100)<br />
DECLARE @newName VARCHAR(100)<br />
IF NOT UPDATE(au_fName) AND NOT UPDATE(au_lName)<br />
BEGIN<br />
RETURN<br />
END<br />
SELECT @oldName = (SELECT au_fName + &#8216; &#8216; + au_lName FROM Deleted)<br />
SELECT @newName = (SELECT au_fName + &#8216; &#8216; + au_lName FROM Inserted)<br />
PRINT &#8216;Name changed from &#8220;&#8216; + @oldName + &#8216;&#8221; to &#8220;&#8216; + @newName + &#8216;&#8221;&#8216;</span></p>
<p><strong><span style="text-decoration: underline;">DELETE TRIGGER</span></strong></p>
<ul>
<li>It has only access to the virtual table &#8220;Deleted&#8221;</li>
<li>Same as INSERT, UPDATE</li>
</ul>
<p><span style="text-decoration: underline;"><strong><span style="color: #0000ff;">ADVANTAGES Of TRIGGERS</span></strong></span></p>
<ol>
<li>When triggers are used correctly, they can save a lot of development work. One of the main benefits of using triggers is that they are stored in a central repository (the database), meaning that they are accessible from all client applications / web pages that can connect to the database.</li>
<li>Before triggers came along, if we had a table that needed to be updated and we wanted to perform some actions after that update, then we would have to &#8220;hard code&#8221; the extra SQL into our application. This meant that if we wanted to change the code later down the track, then each client would need the updated version of our application. This is both annoying and time consuming.</li>
</ol>
<p>Happy Coding <img src='http://www.pritambaldota.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/sql-server-database-triggers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionScript for Designers Part 1- Basics of ActionScript</title>
		<link>http://www.pritambaldota.com/index.php/actionscript-for-designers-part-1-basics-of-actionscript/</link>
		<comments>http://www.pritambaldota.com/index.php/actionscript-for-designers-part-1-basics-of-actionscript/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 09:36:18 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.pritambaldota.com/?p=23</guid>
		<description><![CDATA[Hi Guys, Generally Flash comes with two meanings &#8211; 1) Flash for Designer &#38; 2) Flash for Developers (ActionScript). Designer always threaten about ActionScripting. It is not that complicated at basic level where Designer can levarage the benefits of ActionScripting to their Creative Work without having Programming knowledge. If you already know the Flash, using tools [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Guys,</p>
<p>Generally Flash comes with two meanings &#8211; 1) Flash for Designer &amp; 2) Flash for Developers (ActionScript). Designer always threaten about ActionScripting. It is not that complicated at basic level where Designer can levarage the benefits of ActionScripting to their Creative Work without having Programming knowledge.</p>
<p>If you already know the Flash, using tools and creating animations, you may want to add some interactivity to your skills.</p>
<p>Actionscript is written as a series of statements within a Flash movie, and is placed either in a frame or in an external class file. In the Flash intro class, we also put actionscript on buttons and movieclips, but that was done for the sake of easier learning.</p>
<p>ActionScript, an object oriented programming (OOP) language built for Flash/Flex developement. There are versions of actionscript like Flash (7/8/ cs2 etc..), these are ActionScript 1.0, 1.1, 2.0, 3.0.  Based on the Flash version, adobe provides default scripting version which is located at <strong>Publish Settings</strong> in Flash IDE (Integrated Development Environment).</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #000080;"> 1. TRACE</span></span></strong></p>
<p>Trace function allows you to print information to your output window in Flash. This is not visible to those who view the SWF on the web. Trace is especially useful for debugging, if something goes wrong and you want to figure out why. You can trace simple text or the contents of variables.</p>
<p><strong>trace(”Text or variables can go here”);</strong></p>
<p><strong><span style="color: #000080;"><span style="text-decoration: underline;">2. FUNCTIONS</span></span></strong></p>
<p>Functions are basically reusable chunks of code that you don’t want to rewrite over and over again.  It saves your coding time and add scalability layer to your code.</p>
<p><span style="color: #0000ff;">function</span> myFuncationName(inputValue)<br />
{<br />
 trace(inputValue);<br />
}</p>
<p><strong><span style="color: #000080;"><span style="text-decoration: underline;">3. TIMELINES</span></span></strong></p>
<p>Flash Timeline refers to the sequence of frames and keyframes in either a movieclip or on the Stage or main movie. The stage&#8217;s timeline can be treated in actionscript as an instance of a movieclip. It is represented either as <strong>_root</strong> (from any timeline in the movie which is deeply nested to N-level), or as <strong>_parent</strong> from a movieclip placed on main timeline frames. It is often referred to as the main timeline.</p>
<p><span style="text-decoration: underline;"><span style="color: #000080;"><strong> </strong></span></span></p>
<p><span style="text-decoration: underline;"><span style="color: #000080;"><strong>5. PLAYHEAD CONTROL</strong></span></span></p>
<p>Using simple playhead control, you can take control of your timeline. A lot of animations you can place on timeline which can be easily played using playhead functions. These include:</p>
<div><span style="color: #0000ff;">gotoAndStop<span style="color: #000000;">(frameVariable);</span></span></div>
<div><span style="color: #0000ff;">gotoAndPlay</span> <span style="color: #0000ff;"><span style="color: #000000;">(frameVariable);</span></span></div>
<div><span style="color: #0000ff;"><span style="color: #0000ff;">stop();</span></span></div>
<div><span style="color: #000000;"> </span></div>
<div><span style="color: #000000;"> </span></div>
<div><span style="color: #000000;"> </span><strong><span style="text-decoration: underline;"><span style="color: #000080;">6. ASSIGNING ATTRIBUTES</span></span></strong></div>
<p><strong> </strong><strong> </strong></p>
<p>Assigning attributes allows you to dynamically store or update items in your variables(Container) using Actionscript. This includes visibily, scale, alpha, position etc&#8230; Some examples:</p>
<p>myMovieClip_mc<span style="color: #0000ff;">._visible</span>=false;<br />
myMovieClip_mc.<span style="color: #0000ff;"> _alpha</span>=35;<br />
myMovieClip_mc<span style="color: #0000ff;">._x</span>=50;<br />
myMovieClip_mc.<span style="color: #0000ff;">_y</span>=50;</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #003366;">7. IF STATEMENTS</span></span></strong></p>
<p><strong> </strong><br />
<span style="color: #0000ff;">if</span> statements are used to take decisions inside code. It is straightforward.<br />
<span style="color: #0000ff;">if</span> (myVariable==myOtherVariable)<br />
{<br />
trace(myVariable);<br />
}<br />
<strong>for e.g.</strong><br />
<span style="color: #0000ff;">if</span>(mc_MyMovieCliep<span style="color: #0000ff;">._alpha</span>==50)<br />
{<br />
   <span style="color: #0000ff;">trace</span>(&#8220;Alpha is 50&#8243;);<br />
   //do something<br />
}<br />
else<br />
{<br />
 //do alternative<br />
}</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #000080;">8. FOR LOOP &amp; WHILE LOOP</span></span></strong></p>
<p><strong><span style="text-decoration: underline;"></span></strong><br />
Loops are used to perform specific tasks to certain number of times or until a condition satifies. There are two kind of loops &#8211; FOR loop, &amp; WHILE loop.<br />
for (var startCounter=0; startCounter&lt;5; startCounter++)<br />
{<br />
trace(startCounter);<br />
}</p>
<p>var startCounter=0;<br />
while (startCounter != 10)<br />
{<br />
trace(&#8220;Count &#8220;+ startCounter);<br />
startCounter++;<br />
}</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #000080;">9. BUTTONS</span></span></strong></p>
<p>Buttons can be used to control movies. To accomplish this, you need to attach action to the button or movie clip with the on() function. You could write actions in the Timeline using event handler functions with instance names of button or movie clips or you can write actions on button or movie clips, for this you need to select button or movie clip and Press F9 to open Action window.<br />
<span style="color: #0000ff;">on</span>(<span style="color: #000080;">release</span>)<br />
{<br />
 mc_myMovieClip<span style="color: #0000ff;">._visible</span>=false;<br />
}</p>
<p> </p>
<p>Hope you like this tutorials. I am working on it to proceed further with more detailed one.</p>
<p>Happy Coding <img src='http://www.pritambaldota.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/actionscript-for-designers-part-1-basics-of-actionscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generate Page URL Name for CMS, Blogs Application</title>
		<link>http://www.pritambaldota.com/index.php/generate-page-url-name-for-cms-blogs-application/</link>
		<comments>http://www.pritambaldota.com/index.php/generate-page-url-name-for-cms-blogs-application/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 07:08:00 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">/post/2009/03/31/Generate-Page-URL-Name-for-CMS-Blogs-Application.aspx</guid>
		<description><![CDATA[Hi All, To give the Name to the Page can be handeled by many ways like Using GUID (Issue- Cant identify exactly while browsing through pages) Using Session (Issue-Same as above) Using Page Title provided in Text Field (We will see this) We are going to implement the scenario 3. We will first see what [...]]]></description>
			<content:encoded><![CDATA[<p>Hi All,</p>
<p>
To give the Name to the Page can be handeled by many ways like
</p>
<p><b>Using GUID</b> (Issue- Cant identify exactly while browsing through pages)<br />
<b>Using Session</b> (Issue-Same as above)<br />
<b>Using Page Title</b> provided in Text Field (We will see this)<br />
We are going to implement the scenario 3. We will first see what are our constraints for page url name.</p>
<p>It should be only Alphanumeric enabled like &#8211; About-Us.aspx<br />
No other character should include in the page name like &#8211; %,@,$ etc<br />
Its just about Regular Expression to identify the alphanumeric characters. The reqular expression is in System.Text.RegularExpressions namespace.</p>
<p class="code">
Regex.Replace(strInput, &#8220;[^\\w]&#8220;, &#8220;&#8221;);
</p>
<p>If you give the page Title to &#8211; About % US #$ output will be AboutUs.aspx</p>
<p>Happy Coding <img src='http://www.pritambaldota.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/generate-page-url-name-for-cms-blogs-application/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Database Design Tips &amp; Tricks &#8211; Part 1</title>
		<link>http://www.pritambaldota.com/index.php/database-design-tips-tricks-part-1/</link>
		<comments>http://www.pritambaldota.com/index.php/database-design-tips-tricks-part-1/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 10:47:39 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[asp.net database performance]]></category>
		<category><![CDATA[database tunning]]></category>
		<category><![CDATA[improve performance of database queries in asp.net]]></category>
		<category><![CDATA[sql server tunning]]></category>

		<guid isPermaLink="false">http://www.pritambaldota.com/?p=13</guid>
		<description><![CDATA[Database design is most crucial part in application development. Database can be anything SQL Server, MySQL, Oracle, etc. I will consider SQL SERVER as a part of discussion. Tunning the database depends upon various factors like whether one datatype is better depends on the context of it&#8217;s usage. Following are most common datatypes used in [...]]]></description>
			<content:encoded><![CDATA[<p>Database design is most crucial part in application development. Database can be anything SQL Server, MySQL, Oracle, etc. I will consider SQL SERVER as a part of discussion.</p>
<p>Tunning the database depends upon various factors like whether one datatype is better depends on the context of it&#8217;s usage. Following are most common datatypes used in database.</p>
<p><strong><span style="text-decoration: underline;"><span class="Apple-style-span" style="font-size: small">Numbers Datatype (For storing Primary Keys, Foreign Keys, Status etc)</span></span></strong><span class="Apple-style-span" style="font-size: small"> </span></p>
<p>An int requires 4 times the storage of a tinyint. More storage means more data and</p>
<p>index pages to read / write, more I/O and thus potentially more seek time. It also means more memory consumption.</p>
<p>For eg. Desigining User Role and Users Table. Generally application will not have more than 5-10 user roles like Admin, Manager, Employee, etc. Most of developers design the table like - </p>
<p><strong>Table &#8211; UserRole</strong></p>
<p><strong>RoleId</strong> – Integer (whole number) data from –2^31 (–2,147,483,648) through 2^31–1 (2,147,483,647). It takes 4 Bytes to store.</p>
<p><strong>RoleName</strong> – Varchar (50)</p>
<p>Which is not suiting to our requirements. Instead of int we can use tinyint &#8211; Integer data from 0 to 255. Storage size is 1 byte. </p>
<p> </p>
<p><strong><span style="text-decoration: underline;"><span class="Apple-style-span" style="font-size: small">DateTime Datatype (For storing dates)</span></span></strong></p>
<p>Most of the times database tables required date to be stored to maintain record creation date. </p>
<p><strong>DateTime</strong> data type are stored internally two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of milliseconds after midnight.</p>
<p>The <strong>smalldatetime</strong> data type stores dates and times of day with less precision than datetime. The Database Engine stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight.</p>
<p>So, instead of using datetime as datatype smalldatetime is more efficient in general development.</p>
<p> </p>
<p><strong>STRING DATATYPE (Storing text data)</strong></p>
<p>All string data stored inside varchar, text, ntext, nvarchar, etc. </p>
<p>For eg. FirstName data field developers used varchar or nvarchar with default size i.e. 50. We should know the scope of the filed in terms of maximum characters. Generally first name, last name etc.. won&#8217;t take more than 20 – 25 characters. So instead of 50 if we use 20 characters we can save half the storage, index size which will increase performance of queries. </p>
<p> These are the basics which needs to keep in mind while developing applications. </p>
<p>Happy Coding &#8230; <img src='http://www.pritambaldota.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/database-design-tips-tricks-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GridView in ASP.Net</title>
		<link>http://www.pritambaldota.com/index.php/gridview-in-asp-net/</link>
		<comments>http://www.pritambaldota.com/index.php/gridview-in-asp-net/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 07:20:00 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">/post/2009/03/31/GridView-in-ASPNet.aspx</guid>
		<description><![CDATA[GridView plays very important component in ASP.Net Application. It covers most of the basic reports for which you do not need any reporting component like Crystal Report, Report Viewer etc. Major concern with any data entry form is Add, Edit, Delete and View. Assumptions- We are using SQL Server Express editions as Database. Table Name- [...]]]></description>
			<content:encoded><![CDATA[<p>
GridView plays very important component in ASP.Net Application. It covers most of the basic reports for which you do not need any reporting component like Crystal Report, Report Viewer etc.<br />
</p>
<p>Major concern with any data entry form is Add, Edit, Delete and View.<br />
<br /><b><i><br />
Assumptions-</i></b></p>
<p>We are using SQL Server Express editions as Database.</p>
<p>
Table Name- Employees<br />
<br />
Fields- EmpId, EmpName, Designation
</p>
<p>
Take GridView control on page and set the ID property to dgEmployees.<br />
<br />
Go to property builder by right click on <i>GridView -> Show Smart Tag -> Edit Columns</i>. Uncheck <i>Auto-Generate</i> Field from the Property window.<br />
<br />
Add three TemplateField Column for Employee Name, Designation, &#038; Delete Button. Add Edit button from CommandField Group from Property Window.<br />
<br />
TemplateField Colums have <i>ItemTemplate, Alternating Item Template, Edit Template, Header Template, Footer Template. </i></p>
<p>Each template columns Item Template field contains Label Control &#038; Edit Template contains TextBox control for Editing item. Set the Binding Field name to the Text Property of both controls for each template field to the respective Database Column Name i.e <i>Eval(&#8220;EmpName&#8221;)</i>.
</p>
<p>
Set the DataKeyNames property of GridView to Primary Key Column of DataBase i.e. EmpId. This property binds the database column field value to each row of gridview as a Unique Identifier.<br />
</p>
<p>Set the data bindings for Delete Button for CommandArgument Eval(&#8220;EmpId&#8221;); for saving the ID column value from database for fetching the ID field value while Deleting the Record. Set the CommandName property to Delete Button to CMDDelete. The CommandName property can contain any string name which can be used to recognize the type of command invoked from gridview. Because when any of the event generated in GridVeiw it fires RowCommand Event. In this event we have to handle the Delete Button Code. Instead if you are using default Delete Button of GridView then register for RowDeleting event of GridView and for accessing Unique ID columnvalue from database you need to fetch the id from DataKeys collection of GridView. For e.g.<br />
</p>
<p class="code">
int EmpId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);
</p>
<p>Place the Textbox control in the grids Footer template for Adding new record. Set the CommandName to CMDAdd for Add button.<br />
</p>
<p>Register events for Edit, Update, Cancel button of gridview ??&#8221; RowEditing, RowUpdating, RowCancelEditing.<br />
</p>
<p>
<b>View in GridView</b></p>
<p>
To view data in gridview is very simple. Just create a DataSet using SqlDataAdapter??Ts Fill method and set the GridViews DataSource Property to DataSet.
</p>
<p>Create a Method to Bind the GridView to DataSource named BindGrid. This method fetches data from the GetEmployees method which returns DataSet from Employees table.</p>
<p>Call the BindGrid on Page_Load in !IsPostBack block to fill the grid by default.<br />
</p>
<p class="code">
<pre>
private void BindGrid()

{

dgEmployees.DataSource = GetEmployees();

dgEmployees.DataBind();

}

private DataSet GetEmployees()

{

DataSet ds = new DataSet();

SqlConnection conn = new SqlConnection();

conn.ConnectionString =ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;

SqlDataAdapter da = new SqlDataAdapter("Select * From Employees", conn);

try

{

da.Fill(ds);

return ds;

}

catch { }

finally

{

conn.Close();

conn.Dispose();

}

return null;

}
</pre>
</p>
<p>
<b>Edit in GridView</b></p>
<p>For Editing Register RowEditing event of GridView. To switch the normal mode to Edit mode of gridview EditIndex property plays important role. EditIndex specifies which row is in edit mode by setting RowIndex to it. By default EditIndex of gridview is -1 (Normal mode). If you want to edit 3rd Row then set the EditIndex to 2 (Row index starts from 0,1,2..).<br />
<br />
After setting editindex refresh the grid by calling BinGrid. GridViewEditEventArgs object knows the current row index so getting row index of the selected row in gridveiw is not big deal; just e.NewEditIndex (e object of GridViewEditEventArgs).<br />
</p>
<p class="code">
<pre>
protected void dgEmployees_RowEditing(object sender, GridViewEditEventArgs e)

{

dgEmployees.EditIndex = e.NewEditIndex;

BindGrid();

}
</pre>
</p>
<p><b><br />
Cancel in GridView</b><br />
<br />
For Cancel just reset the GridView editindex to default i.e. -1 and refresh the grid.</p>
<p class="code">
<pre>
protected void dgEmployees_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

{

dgEmployees.EditIndex = -1;

BindGrid();

}
</pre>
</p>
<p>
<b><br />
Update in GridView<br />
</b><br />
For Update register RowUpdating event of the gridview. Find the Unique id for updating the row from DataKeys collection of gridview.<br />
</p>
<p class="code">
int EmpId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);
</p>
<p></p>
<p>Find the controls in the selected row by using FindControl method of gridviews rows collection and collect data from the text boxes.<br />
</p>
<p class="code">
TextBox txtname = dgEmployees.Rows[e.RowIndex].FindControl(&#8220;txtEmpName&#8221;) as TextBox;<br />
<br />
TextBox txtdesign = dgEmployees.Rows[e.RowIndex].FindControl(&#8220;txtDesignation&#8221;) as TextBox;
</p>
<p>Finally update the row and refresh the grid.</p>
<p class="code">
<pre>
if(txtname!=null &#038;&#038; txtdesign!=null)

UpdateEmployee(empId, txtname.Text.Trim(), txtdesign.Text.Trim());

dgEmployees.EditIndex = -1;

BindGrid();
</pre>
</p>
<p><b><br />
Complete code-<br />
</b></p>
<p class="code">
<pre>
protected void dgEmployees_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

int empId = Convert.ToInt32(dgEmployees.DataKeys[e.RowIndex].Value);

//Find Text boxex

TextBox txtname = dgEmployees.Rows[e.RowIndex].FindControl("txtEmpName") as TextBox;

TextBoxtxtdesign=dgEmployees.Rows[e.RowIndex].FindControl("txtDesignation") as TextBox;

if(txtname!=null &#038;&#038; txtdesign!=null)

UpdateEmployee(empId, txtname.Text.Trim(), txtdesign.Text.Trim());

dgEmployees.EditIndex = -1;

BindGrid();

}
</pre>
</p>
<p><b><br />
Custom Delete in GridView<br />
</b><br />
For Delete register RowCommand event of the gridview. Find the Unique id for deleting the row from DataKeys collection of gridview. Check for CommanName and invoke delete method for the selected row.</p>
<p class="code">
<pre>
protected void dgEmployees_RowCommand(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName.Equals("CMDDelete"))

{

int EmpId = Convert.ToInt32(e.CommandArgument);

DeleteEmployee(EmpId);

//Refresh Grid

BindGrid();

}

}
</pre>
</p>
<p>
<b><br />
Add in GridView<br />
</b><br />
Adding from GridView is just some trick with Footer Template. I added textboxes and a add button in the footer row of the gridview. When u are in Normal mode it is visible else it is invisible to synchronize between edit and add.<br />
<br />
Like Updating find the Textbox and pass the values to Addemployee method like<br />
</p>
<p class="code">
<pre>
else if (e.CommandName.Equals("CMDAdd"))

{

TextBox txtname = dgEmployees.FooterRow.FindControl("txtEmpName") asTextBox;

TextBox txtdesign = dgEmployees.FooterRow.FindControl("txtDesignation") as TextBox;

if (txtname != null &#038;&#038; txtdesign != null)

{

AddEmployee(txtname.Text.Trim(), txtdesign.Text.Trim());

BindGrid();

}

}</pre>
</p>
<p>The Complete code for EditEmployee, AddEmployee, UpdateEmployee, DeleteEmployee is in Source File.</p>
<p></p>
<p>The code should be in RowCommand event only. Due to this we use CommandName for different button control to differentiate between the type of code to be handled by gridview.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/gridview-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>ASP.Net Server Variables</title>
		<link>http://www.pritambaldota.com/index.php/asp-net-server-variables/</link>
		<comments>http://www.pritambaldota.com/index.php/asp-net-server-variables/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 07:18:00 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">/post/2009/03/31/ASPNet-Server-Variables.aspx</guid>
		<description><![CDATA[Below is the detailed table for showing the ServerVariables Collection information. Variable Name Description ALL_HTTP HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:sv HTTP_HOST:localhost:1229 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) ALL_RAW Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: sv Host: localhost:1229 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT [...]]]></description>
			<content:encoded><![CDATA[<p>Below is the detailed table for showing the ServerVariables Collection information.</p>
<table id="GridView1" style="FONT-SIZE: 12px; FONT-FAMILY: Verdana; BORDER-COLLAPSE: collapse" border="1" cellspacing="2" cellpadding="2" rules="all">
<tbody>
<tr>
<th>Variable Name</th>
<th>Description</th>
</tr>
<tr>
<td><span id="GridView1_ctl02_lblName">ALL_HTTP</span></td>
<td><span id="GridView1_ctl02_lblValue">HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:sv HTTP_HOST:localhost:1229 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) </span></td>
</tr>
<tr>
<td><span id="GridView1_ctl03_lblName">ALL_RAW</span></td>
<td><span id="GridView1_ctl03_lblValue">Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: sv Host: localhost:1229 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) </span></td>
</tr>
<tr>
<td><span id="GridView1_ctl04_lblName">APPL_MD_PATH</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl05_lblName">APPL_PHYSICAL_PATH</span></td>
<td><span id="GridView1_ctl05_lblValue">D:\code\web\demos\membership\</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl06_lblName">AUTH_TYPE</span></td>
<td><span id="GridView1_ctl06_lblValue">NTLM</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl07_lblName">AUTH_USER</span></td>
<td><span id="GridView1_ctl07_lblValue">SYSTEMEN-D9AE02\Stefan Holmberg</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl08_lblName">AUTH_PASSWORD</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl09_lblName">LOGON_USER</span></td>
<td><span id="GridView1_ctl09_lblValue">SYSTEMEN-D9AE02\Stefan Holmberg</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl10_lblName">REMOTE_USER</span></td>
<td><span id="GridView1_ctl10_lblValue">SYSTEMEN-D9AE02\Stefan Holmberg</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl11_lblName">CERT_COOKIE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl12_lblName">CERT_FLAGS</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl13_lblName">CERT_ISSUER</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl14_lblName">CERT_KEYSIZE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl15_lblName">CERT_SECRETKEYSIZE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl16_lblName">CERT_SERIALNUMBER</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl17_lblName">CERT_SERVER_ISSUER</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl18_lblName">CERT_SERVER_SUBJECT</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl19_lblName">CERT_SUBJECT</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl20_lblName">CONTENT_LENGTH</span></td>
<td><span id="GridView1_ctl20_lblValue">0</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl21_lblName">CONTENT_TYPE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl22_lblName">GATEWAY_INTERFACE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl23_lblName">HTTPS</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl24_lblName">HTTPS_KEYSIZE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl25_lblName">HTTPS_SECRETKEYSIZE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl26_lblName">HTTPS_SERVER_ISSUER</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl27_lblName">HTTPS_SERVER_SUBJECT</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl28_lblName">INSTANCE_ID</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl29_lblName">INSTANCE_META_PATH</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl30_lblName">LOCAL_ADDR</span></td>
<td><span id="GridView1_ctl30_lblValue">127.0.0.1</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl31_lblName">PATH_INFO</span></td>
<td><span id="GridView1_ctl31_lblValue">/membership/servervariables.aspx</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl32_lblName">PATH_TRANSLATED</span></td>
<td><span id="GridView1_ctl32_lblValue">D:\code\web\demos\membership\servervariables.aspx</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl33_lblName">QUERY_STRING</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl34_lblName">REMOTE_ADDR</span></td>
<td><span id="GridView1_ctl34_lblValue">127.0.0.1</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl35_lblName">REMOTE_HOST</span></td>
<td><span id="GridView1_ctl35_lblValue">127.0.0.1</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl36_lblName">REMOTE_PORT</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl37_lblName">REQUEST_METHOD</span></td>
<td><span id="GridView1_ctl37_lblValue">GET</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl38_lblName">SCRIPT_NAME</span></td>
<td><span id="GridView1_ctl38_lblValue">/membership/servervariables.aspx</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl39_lblName">SERVER_NAME</span></td>
<td><span id="GridView1_ctl39_lblValue">localhost</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl40_lblName">SERVER_PORT</span></td>
<td><span id="GridView1_ctl40_lblValue">1229</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl41_lblName">SERVER_PORT_SECURE</span></td>
<td><span id="GridView1_ctl41_lblValue">0</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl42_lblName">SERVER_PROTOCOL</span></td>
<td><span id="GridView1_ctl42_lblValue">HTTP/1.1</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl43_lblName">SERVER_SOFTWARE</span></td>
<td> </td>
</tr>
<tr>
<td><span id="GridView1_ctl44_lblName">URL</span></td>
<td><span id="GridView1_ctl44_lblValue">/membership/servervariables.aspx</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl45_lblName">HTTP_CONNECTION</span></td>
<td><span id="GridView1_ctl45_lblValue">Keep-Alive</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl46_lblName">HTTP_ACCEPT</span></td>
<td><span id="GridView1_ctl46_lblValue">*/*</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl47_lblName">HTTP_ACCEPT_ENCODING</span></td>
<td><span id="GridView1_ctl47_lblValue">gzip, deflate</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl48_lblName">HTTP_ACCEPT_LANGUAGE</span></td>
<td><span id="GridView1_ctl48_lblValue">sv</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl49_lblName">HTTP_HOST</span></td>
<td><span id="GridView1_ctl49_lblValue">localhost:1229</span></td>
</tr>
<tr>
<td><span id="GridView1_ctl50_lblName">HTTP_USER_AGENT</span></td>
<td><span id="GridView1_ctl50_lblValue">Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)</span></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/asp-net-server-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storing Objects into Permanant DataStore in ASP.Net</title>
		<link>http://www.pritambaldota.com/index.php/storing-objects-into-permanant-datastore-in-asp-net/</link>
		<comments>http://www.pritambaldota.com/index.php/storing-objects-into-permanant-datastore-in-asp-net/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 07:12:00 +0000</pubDate>
		<dc:creator>Pritam Baldota</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">/post/2009/03/31/Storing-Objects-into-Permanant-DataStore-in-ASPNet.aspx</guid>
		<description><![CDATA[Hi All, I was facing a problem towards sharing a data between Flash and .Net. The easiest way i found is XML Seralization because Remoting is much heavy and it requires remoting implementation. Even now I can store the Calss objects permanantely. This can be used in concept of Hibernate (Some what at very basic [...]]]></description>
			<content:encoded><![CDATA[<p>Hi All,</p>
<p>
I was facing a problem towards sharing a data between Flash and .Net. The easiest way i found is XML Seralization because Remoting is much heavy and it requires remoting implementation. Even now I can store the Calss objects permanantely. This can be used in concept of Hibernate (Some what at very basic level).
</p>
<p>
I found XML Seralization because there must be some common bridge between two different technoloiges for communication. XML will act as common bridge between .Net and Flash.</p>
<p>
XML Seralization can be done by System.Xml.Serialization.XmlSerializer class from System.Xml.Serialization namespace.
</p>
<p>
Assume our class defination looks like below -
</p>
<p><pre>
namespace EShopping
{
public class Category
{
private int _CategoryId;
public string CatName;
public int CategoryId
{
get{return _CategoryId;}
set{_CategoryId=value;}
}
}
}
</pre>
</p>
<p>Our object has below contents-
</p>
<p>
EShopping.Category c = new EShopping.Category();<br />
c.CategoryId = 1;<br />
c.CatName = &#8220;Hello&#8221;;
</p>
<p>
Now we want to seralize this object to the XML by XML Seralization.
</p>
<p>
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));
</p>
<p>
XmlSerializer Class has a method called Seralize and Deserialize.<br />
Seralize method requires parameter Textwriter and class object to seralize.</p>
<p>
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));<br />
<br />
System.IO.TextWriter tw = new System.IO.StreamWriter(Server.MapPath(&#8220;SeralizeClass.xml&#8221;));<br />
<br />
ser.Serialize(tw, c);<br />
<br />
tw.Close();
</p>
<p>
That&#8217;s it. Now you can see the SeralizeClass.xml file in your Web root directory. You can access this into any of the technologies which has xml support.
</p>
<p>
Accessing Seralize Object into .Net-<br />
<br />
This is pretty straight forward and just access the object by Deserialize methotd of XmlSerializer Class.
</p>
<p>System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(EShopping.Category));</p>
<p>System.IO.TextReader tr = new System.IO.StreamReader(Server.MapPath(&#8220;SeralizeClass.xml&#8221;));</p>
<p>EShopping.Category c = (EShopping.Category)ser.Deserialize(tr);</p>
<p>tr.Close();</p>
<p>Happy Coding <img src='http://www.pritambaldota.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pritambaldota.com/index.php/storing-objects-into-permanant-datastore-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

