<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1097389643353265797</id><updated>2012-02-07T10:48:45.864+05:30</updated><category term='TEXTVALID'/><category term='UPDATETEXT'/><category term='Data Flow Task'/><category term='Parsing Erroe'/><category term='ISNUMERIC'/><category term='Reporting Service Web Service'/><category term='Html FIle Upload'/><category term='Encoding'/><category term='Delpoy report'/><category term='Database Information'/><category term='Cast'/><category term='UTF'/><category term='Column Information'/><category term='Initial Visibility'/><category term='Update Panel'/><category term='View All Trigger'/><category term='All Column'/><category term='Dynamic Report'/><category term='Ajax File Upload'/><category term='XML Encoding Problem'/><category term='XmlWriter'/><category term='validation'/><category term='Databind'/><category term='Iframe File Upload'/><category term='datalist'/><category term='rownumber'/><category term='data type mix'/><category term='InitialToogleState'/><category term='Dynamic Toogle'/><category term='File Upload'/><category term='SSIS'/><category term='sql server 2005'/><category term='Age Calculation'/><category term='Error sql server'/><category term='Resize window'/><category term='Age'/><category term='Expand'/><category term='custom paging'/><category term='PageRequestManager'/><category term='centre'/><category term='Child'/><category term='READTEXT'/><category term='DateDiff'/><category term='Javascript'/><category term='Reporting Service'/><category term='GridView'/><category term='Xml Encoding'/><category term='Date Difference'/><category term='Popup'/><category term='paging in datalist'/><category term='Screen heinght'/><category term='XML'/><category term='ResizeWindow'/><category term='move'/><category term='Table Information'/><category term='VB.net'/><category term='Keep Session'/><category term='text'/><category term='row number sql server 2000'/><category term='Data Set'/><category term='Parent'/><category term='Infinite Session'/><category term='move popup'/><category term='ISNUMERIC PROBLEM'/><category term='ASP.Net'/><category term='Column'/><category term='Session Object'/><category term='Max'/><category term='width'/><category term='position popup'/><category term='ASP.Net 2.0'/><category term='Trigger'/><category term='Collapse Group'/><category term='.Net'/><category term='paging'/><category term='event'/><category term='All Database'/><category term='validator'/><category term='Add Row'/><category term='Datatable'/><category term='Ajax'/><category term='Drill Down Report'/><category term='GetDate'/><category term='Ascii'/><category term='Postion window'/><category term='dataview'/><category term='Session Expire'/><category term='Parameter'/><category term='WRITETEXT'/><category term='All Tables'/><category term='Age on Today'/><category term='Shared Data Source'/><category term='Oledb Destination'/><category term='Write XML Namespace'/><category term='sql server 2000'/><category term='paging in repeater'/><category term='ntext'/><category term='sorting'/><category term='Table Schema'/><category term='Balk Data'/><category term='Toogle Group'/><category term='Aggregate Function'/><category term='sql server'/><category term='C#'/><category term='Report Specific Data Source'/><category term='TEXTPTR'/><category term='repeater'/><category term='objectdatasource'/><category term='ScriptManager'/><category term='Generate RDL'/><category term='Expand Group'/><category term='Change Encoding'/><category term='expand with query string'/><category term='Ado.Net'/><category term='middle'/><title type='text'>On the way of being a .Net Developer</title><subtitle type='html'>In this blog i shall explore the challanges i faced in my development carrier as an asp.net developer. It will contain the solution of the problems. And also the new thinks i have learned through my job. It is all about asp.net,.net,c#,ajax,sql srver,reporting service,sharepoint and all other upcomin technologies related with microsoft platform which i am leaning and will learn.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-3866712955773912081</id><published>2009-10-13T16:49:00.005+05:30</published><updated>2009-10-13T18:42:48.281+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='objectdatasource'/><category scheme='http://www.blogger.com/atom/ns#' term='custom paging'/><category scheme='http://www.blogger.com/atom/ns#' term='paging'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='dataview'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Custom paging in Gridview With ObjectDataSource</title><content type='html'>Many times we use paging with GridView with AllowPaging = "True" and binding the GridView with some ObjectDataSource. It actually fetches all row from the database and depending on the no of records it fetched, it generates the Pager section of the page and according to the current page index, it shows the set of record.&lt;br /&gt;This approach is good for when you have limited no of record in the database. But there are many situations where there is thousands of rows in the database and you have to display only 25 records(PageSize) out of that thousands of records. So it is not good practice to fetch all record through object datasource to display only 25 records.&lt;br /&gt;Here we should use custom paging to fetch only the 25 rows starting from the startindex which is&lt;br /&gt;CurrentPageIndex*PageSize (As Index is 0 Based).&lt;br /&gt;Calculated automatically by objectdatasource.&lt;br /&gt;Here is the change you have to do&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Set EnablePaging="True" for ObjectDataSource&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Set The SelectMethod Property&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Set value for following Properties of ObjecDataSource StartRowIndexParameterName, SortParameterName, MaximumRowsParameterName&lt;br /&gt;These parameters needs to be present in the method attached for selecting the result for objectdatasource.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Set SelectCountMethod to the name of method returning the total no of rows.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;Here is my ObjectDataSourceCode&lt;br /&gt;&lt;div style="overflow:auto"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;asp:objectdatasource id="objDS" runat="server" enablepaging="True" selectmethod="SearchResult" typename="PRP.BusinessLogic.TpilTblNsefaoscripmaster" startrowindexparametername="paramStartRowIndex" sortparametername="paramSortExpression" maximumrowsparametername="paramPageSize" selectcountmethod="GetNoOfRows"&amp;gt;&lt;br /&gt;          &amp;lt;selectparameters&amp;gt;&lt;br /&gt;              &amp;lt;asp:parameter name="paramSymbol" type="String"&amp;gt;&lt;br /&gt;                 &amp;lt;asp:parameter direction="Output" name="paramTotalNoOfRows" type="Int32"&amp;gt;&lt;br /&gt;                 &amp;lt;/asp:parameter&amp;gt;&lt;br /&gt;             &amp;lt;/asp:parameter&amp;gt;&lt;br /&gt;         &amp;lt;/selectparameters&amp;gt;&lt;br /&gt;&amp;lt;/asp:objectdatasource&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The SearchResult &amp;amp; GetNoOfRows Function&lt;br /&gt;&lt;div style='overflow:auto'&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public DataTable SearchResult(string paramSymbol,&lt;br /&gt;       int paramStartRowIndex, int paramPageSize, string paramSortExpression, out int paramTotalNoOfRows)&lt;br /&gt;{&lt;br /&gt;  TpilTblNsefaoscripmasterHelper.SearchResult(paramSymbol, paramStartRowIndex, paramStartRowIndex + paramPageSize, paramSortExpression, ref paramTotalNoOfRows);&lt;br /&gt;  this.totalNoOfRows = paramTotalNoOfRows;&lt;br /&gt;}&lt;br /&gt;int totalNoOfRows = 0;&lt;br /&gt;public int GetNoOfRows(string paramSymbol,&lt;br /&gt;       int paramStartRowIndex, int paramPageSize, string paramSortExpression, out int paramTotalNoOfRows)&lt;br /&gt;{&lt;br /&gt;   paramTotalNoOfRows = totalNoOfRows;&lt;br /&gt;   return totalNoOfRows;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The parameter list for both the functions are same but the second function retuns int no of rows. But i don't have used two function call for getting the total noofrows. Inside select function i have set the totalNoOfRows parameter which is accessed inside GetNoOfRows method to get the no of rows. This works as objectdatasource calls both the method on same object instance of the class and none of the methods and the class variable is static and the select methos is called first and then the row count method is called.&lt;br /&gt;Now check the stored procedure used for this purpose&lt;br /&gt;&lt;div style="overflow:auto"&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Create PROCEDURE [dbo].[USP_TPIL_tbl_NSEFAOScripSelectForSearch]&lt;br /&gt;@Symbol varchar(50),&lt;br /&gt;@StartIndex int = 0,&lt;br /&gt;@EndIndex int =25,&lt;br /&gt;@SortExpression varchar(50),&lt;br /&gt;@TotalNoOfRows int OUTPUT&lt;br /&gt;AS&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;Select * from&lt;br /&gt;(&lt;br /&gt;SELECT m.Instrument,m.Symbol,m.SymbolDescription,ExpiryDate,&lt;br /&gt;Row_Number() OVER (Order By&lt;br /&gt;     CASE WHEN @SortExpression='EXPIRYDATE' OR @SortExpression='EXPIRYDATE ASC' THEN m.EXPIRYDATE END DESC,&lt;br /&gt;     CASE WHEN @SortExpression='EXPIRYDATE DESC' THEN m.EXPIRYDATE END ASC ,&lt;br /&gt;     CASE WHEN @SortExpression='SYMBOL' OR @SortExpression='SYMBOL ASC' THEN m.SYMBOL END DESC,&lt;br /&gt;     CASE WHEN @SortExpression='SYMBOL DESC' THEN m.SYMBOL END ASC&lt;br /&gt;    ) as RowNumber &lt;br /&gt;FROM&lt;br /&gt;[dbo].[TPILl_NSEFAOScripMaster] m&lt;br /&gt;WHERE &lt;br /&gt;(m.[Symbol] LIKE @Symbol OR @Symbol = '')&lt;br /&gt;)t&lt;br /&gt;Where RowNumber&gt;@StartIndex  AND RowNumber&lt;=@EndIndex   --return SELECT @TotalNoOfRows = Count(*)  FROM   [dbo].[TPILl_NSEFAOScripMaster] m  WHERE    (m.[Symbol] LIKE @Symbol OR @Symbol = '') &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;As i am using Sql Server 2005, i used ROW_Number() function. The value of output parameter "TotalNoOfRows " is set to the variable "totalNoOfRows" inside "SearchResult" function.&lt;br /&gt;To know about how to get Row Number in Sql Server 2000 please check the bottom of this &lt;a href="http://aspxdev.blogspot.com/2009/02/paging-in-datalist-and-repeater.html"&gt;link&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-3866712955773912081?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/3866712955773912081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=3866712955773912081' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3866712955773912081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3866712955773912081'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/10/custom-paging-in-gridview-with.html' title='Custom paging in Gridview With ObjectDataSource'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-7102510784608991672</id><published>2009-04-16T18:07:00.004+05:30</published><updated>2009-04-16T18:34:30.668+05:30</updated><title type='text'>Focus the first control of your page</title><content type='html'>In all pages we have to put the focus on the first control of the page. It can be a textbox,a radio button, a checkbox, a select field, a textarea or a button. For my current project i have created a function which i have placed inside the masterpage and it will traverse through the page starting from a particular control (inside the control) and will take the first occurance of the above types of control and will put the cursor focus on the control. Below is the javascript code i used to achieve this&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;     function selectFirstControl()&lt;br /&gt;     {&lt;br /&gt;         var objIP = getFocusableControl(document.getElementById('tdContentBody'));&lt;br /&gt;         if(objIP!=null)&lt;br /&gt;         {&lt;br /&gt;             objIP.focus();&lt;br /&gt;             return;&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;  &lt;br /&gt;     function getFocusableControl(parentCtrl)&lt;br /&gt;     {&lt;br /&gt;         if(!$(parentCtrl).visible())&lt;br /&gt;             return null;&lt;br /&gt;          if(parentCtrl.tagName == "INPUT")&lt;br /&gt;          {&lt;br /&gt;             if(parentCtrl.getAttribute("type")=="hidden")&lt;br /&gt;             {&lt;br /&gt;                 return null;&lt;br /&gt;             }&lt;br /&gt;             return parentCtrl;&lt;br /&gt;          }&lt;br /&gt;          else          &lt;br /&gt;          {&lt;br /&gt;             if(parentCtrl.tagName == "SELECT")&lt;br /&gt;             {&lt;br /&gt;                 return parentCtrl;&lt;br /&gt;             }&lt;br /&gt;          }&lt;br /&gt;          var children = $(parentCtrl).childElements();&lt;br /&gt;         for(var i = 0;i&amp;lt;children.length;i++)&lt;br /&gt;            {&lt;br /&gt;               var resCtrl = getFocusableControl(children[i]);&lt;br /&gt;               if(resCtrl != null)&lt;br /&gt;                   return resCtrl;&lt;br /&gt;            }&lt;br /&gt;       }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Call the function selectFirstControl(); from the bottom of  your page.&lt;br /&gt;Here i have called the function "getFocusableControl" recursively to get the control. It is checking the tagname of the node, if it is "Input" or "Select" then it is excluding the hidden fields by checking the type property for for inputs and if it is not hidden, then it is putting the focus on the control.&lt;br /&gt;Iam checking if the parent control visible or not with $(parentCtrl).visible() which is a function from prototypejs to check the visibility. But this checks for the inline "display" property of the element, if "display :none" it returns false. But it cannot check if you are using the hidden property of hiding the control with stylesheet class.&lt;br /&gt;If you are not using prototypejs, you can check the direct style property of the control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-7102510784608991672?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/7102510784608991672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=7102510784608991672' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7102510784608991672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7102510784608991672'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/04/focus-first-control-of-your-page.html' title='Focus the first control of your page'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-7109571142109290375</id><published>2009-04-07T19:38:00.010+05:30</published><updated>2009-04-16T18:00:20.216+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='event'/><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='ScriptManager'/><category scheme='http://www.blogger.com/atom/ns#' term='GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Trigger Html/Javascript Event from Javascript</title><content type='html'>In many situation i had to trigger JavaScript Event from code. Like click on a button when something happened to post the page. It mainly comes into picture when i use UpdatePanel or using modalpopup for click on a button inside grid/list/gridview ect.  This creation of event is very much dependent on the browser. Here is the code to trigger a button click event&lt;br /&gt;&lt;pre&gt;&lt;code&gt;function clickButton()&lt;br /&gt;{&lt;br /&gt;if( document.createEvent )&lt;br /&gt;{&lt;br /&gt; var evObj = document.createEvent('MouseEvents');&lt;br /&gt; evObj.initMouseEvent( 'click', true, false, window, 0, 12, 345, 7, 220, false, false, true, false, 0, null );&lt;br /&gt; $(' btnTransRefresh').dispatchEvent(evObj);&lt;br /&gt;}&lt;br /&gt;        else&lt;br /&gt;if( document.createEventObject )&lt;br /&gt;{&lt;br /&gt;    $('btnTransRefresh').fireEvent('onChange');&lt;br /&gt;}&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;/pre&gt;Here i am using Prototyprjs framework, so you see the "$". You can replace those with document.getElementById('') syntax.&lt;br /&gt;initMouseEvent takes the following parameters.&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: left;"&gt;&lt;code&gt;initMouseEvent( 'type', bubbles, cancelable, windowObject, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget )&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In many scenarios we do some javascript calculation on change of value in some particular textboxes. But in some scenarios, the value in the textbox on change of which we need to calculate is done through some javascript. Like in my project i was using calender from ajax control toolkit which is inside a project specific control names PRPCalender. In some pages i had to do some calculations only when the value in calender is changed. So i could not use the javascript events associated with the calender control (ajax). So i decided to go with triggering onchange event as the textbox showing the calender control doesn't fire the onchange event as the value is changed through JavaScript.&lt;br /&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;string methodName = "prpCalenderDateChanged" + txtCalendar.ClientID;&lt;br /&gt;calendarExtender.OnClientDateSelectionChanged = methodName;&lt;br /&gt;System.Text.StringBuilder sb = new System.Text.StringBuilder();&lt;br /&gt;sb.AppendFormat(@"&lt;br /&gt;  function {0}(sender,eArg)&lt;br /&gt;  {{&lt;br /&gt;      //alert('Calender Date Changed');      &lt;br /&gt;      var tbId = '{1}';&lt;br /&gt;      //$(tbId).blur();&lt;br /&gt;      //$(tbId).focus();&lt;br /&gt;      if( document.createEvent )&lt;br /&gt;      {{&lt;br /&gt;          var evObj = document.createEvent('HTMLEvents');&lt;br /&gt;          evObj.initEvent( 'onchange', true, false);&lt;br /&gt;          $(tbId).dispatchEvent(evObj);&lt;br /&gt;      }}&lt;br /&gt;      else&lt;br /&gt;          if( document.createEventObject )&lt;br /&gt;          {{&lt;br /&gt;              $(tbId).change();&lt;br /&gt;          }}&lt;br /&gt;  }}&lt;br /&gt;", methodName, txtCalendar.ClientID);&lt;br /&gt;ScriptManager.RegisterStartupScript(this, this.GetType(), "textChanged" + txtCalendar.ClientID, sb.ToString(), true);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;Here inside my calender control PRPCalender, i am registering a function which is unique for each calender control inside any page (i am using the client id as concatined to generate the method name) which fires the onchange event on the textbox.&lt;br /&gt;&lt;pre  style="font-weight: bold; color: rgb(51, 51, 255);font-family:verdana;"&gt;&lt;span style="font-size:130%;"&gt;&lt;code&gt;calendarExtender.OnClientDateSelectionChanged = methodName;&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;which is called by toolkit JS when the&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;date value is changed.&lt;br /&gt;Some Useful Link &lt;a href="http://www.howtocreate.co.uk/tutorials/javascript/domevents"&gt;Link1&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-7109571142109290375?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/7109571142109290375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=7109571142109290375' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7109571142109290375'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7109571142109290375'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/04/trigger-htmljavascript-event-from.html' title='Trigger Html/Javascript Event from Javascript'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-6162585548318851166</id><published>2009-03-26T12:22:00.008+05:30</published><updated>2009-03-26T12:53:15.788+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SSIS'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='Oledb Destination'/><category scheme='http://www.blogger.com/atom/ns#' term='Trigger'/><category scheme='http://www.blogger.com/atom/ns#' term='Data Flow Task'/><title type='text'>Trigger not working when importing data with SSIS package</title><content type='html'>I am very new to SSIS package. Actually i am not a hardcode SQL guy, so i never needed to work with SSIS before. In my current project i needed to import data after fetching from a server with FTP and then extract the ZIP files and insert it into respective tables. For eatracting ZIP files i used "SharpZipLib" which is open source library for dot net. Then i created a temp table in which i first inserted to remove duplicate. Remember, i created the temp table on the fly inside the "Execute SQL Task" with create table statement and after insert to the original table i deleted the table. In this scenario you have to change the "DelayValidation" property of the "Data Flow Task" to "true" (By default it is false). Otherwise you will get some validation error as the temp table in which you are going to insert data is not present now, it is created on the fly and deleted after insert is completed.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_7BJz2MaZ-L0/Scsrc_VC7xI/AAAAAAAAANU/0y8zQPcJh1k/s1600-h/Advanced+Editor.png"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 248px; height: 235px;" src="http://3.bp.blogspot.com/_7BJz2MaZ-L0/Scsrc_VC7xI/AAAAAAAAANU/0y8zQPcJh1k/s320/Advanced+Editor.png" alt="" id="BLOGGER_PHOTO_ID_5317391562077040402" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Now in my case i had a trigger which need to fire each time i instered some data into the table. Actually, i was updating the stock rate and needed to copy the rate by trigger. But to my surprise, the trigger was not firing when i insert/update the data by the SSIS. But the trigger fires when i do the update by SQL.&lt;br /&gt;The problem is with the settings in "OleDB Destination" inside "Data Flow Task".  Here is how i solved the issue&lt;br /&gt;Right click on th "OldeDB Destination" and you will find "Show Advanced Editor" and open the Advanced editor.&lt;br /&gt;&lt;br /&gt;In the editor check the "FastLoadOptions" which is by default "TABLOCK,CHECK_CONSTRAINTS". You need to add one more option "FIRE_TRIGGERS" . And thats it. But remember the trigger runs once for each update/insert. &lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_7BJz2MaZ-L0/ScsrSLQTRZI/AAAAAAAAANM/nh0IIOxfHeM/s1600-h/Advanced+Editor1.png"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 316px; height: 320px;" src="http://1.bp.blogspot.com/_7BJz2MaZ-L0/ScsrSLQTRZI/AAAAAAAAANM/nh0IIOxfHeM/s320/Advanced+Editor1.png" alt="" id="BLOGGER_PHOTO_ID_5317391376299804050" border="0" /&gt;&lt;/a&gt;Not for every update/insert. So in case where we are doing batch update, you must write the trigger code in such a way that it will be able to handle the situation for multiple row sets. Here is a sample statement&lt;br /&gt;&lt;pre id="codeSnippet11738" class="prettyprint"&gt;CREATE TRIGGER UpdateStockRate&lt;br /&gt;ON INV_tbl_StockMaster&lt;br /&gt;AFTER INSERT,Update&lt;br /&gt;AS&lt;br /&gt;                                                                                                            &lt;br /&gt;UPDATE t&lt;br /&gt;SET CMP = i.LastTradedPrice&lt;br /&gt;FROM INV_tbl_Holding t&lt;br /&gt;JOIN INSERTED i&lt;br /&gt; ON i.Symbol = t.Symbol&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-6162585548318851166?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/6162585548318851166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=6162585548318851166' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6162585548318851166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6162585548318851166'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/03/trigger-not-working-when-importing-data.html' title='Trigger not working when importing data with SSIS package'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_7BJz2MaZ-L0/Scsrc_VC7xI/AAAAAAAAANU/0y8zQPcJh1k/s72-c/Advanced+Editor.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-4160174950372942389</id><published>2009-02-27T11:03:00.002+05:30</published><updated>2009-02-27T11:07:14.328+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service'/><title type='text'>Reporting Service Custom Code Add Assembly</title><content type='html'>For adding assembly you have to copy the .dll assembly file to the following location "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies" folder.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-4160174950372942389?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/4160174950372942389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=4160174950372942389' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4160174950372942389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4160174950372942389'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/02/reporting-service-custom-code-add.html' title='Reporting Service Custom Code Add Assembly'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-1225189609987624562</id><published>2009-02-20T17:21:00.009+05:30</published><updated>2009-07-23T12:04:50.952+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='paging in datalist'/><category scheme='http://www.blogger.com/atom/ns#' term='repeater'/><category scheme='http://www.blogger.com/atom/ns#' term='paging in repeater'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='row number sql server 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='custom paging'/><category scheme='http://www.blogger.com/atom/ns#' term='rownumber'/><category scheme='http://www.blogger.com/atom/ns#' term='paging'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='sorting'/><category scheme='http://www.blogger.com/atom/ns#' term='datalist'/><title type='text'>Paging in Datalist and Repeater</title><content type='html'>Datalist and Repeater doesn't provide any paging by default like gridview or datagrid. So we avoid using datagrid/repeater as much as possible. But there comes situation where using datalist or repeater is easier to maintain the design for the page. Like some product is displayed like row by row with 4 producs in a single w. There its tough to achieve (but not impossible) this design output wit datagrid/gridview. So we choose datalist making its RepeatColumns="4" RepeatDirection="Horizontal".&lt;br /&gt;But paging???&lt;br /&gt;So i created a control named as COUSPaging (Cous is my project name). Which contains two link buttons as "Next" and "Previous" and a textbox for goto page as below&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_7BJz2MaZ-L0/SZ6g3N_q8YI/AAAAAAAAAM8/glECEOP-OsM/s1600-h/Paging.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 32px;" src="http://3.bp.blogspot.com/_7BJz2MaZ-L0/SZ6g3N_q8YI/AAAAAAAAAM8/glECEOP-OsM/s320/Paging.png" alt="" id="BLOGGER_PHOTO_ID_5304854281598988674" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In my control i used a public event "PageIndexChanging" which is of type GridViewPageEventHandler, so that it sends the same parameter as GridView. The event is handled from the Parent page containg the DataList.&lt;br /&gt;The Paging.aspx Page Code:&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt; &amp;lt;tr&amp;gt;&lt;br /&gt;     &amp;lt;td&amp;gt;&lt;br /&gt;         &amp;lt;asp:LinkButton ID="linkPrevious" CssClass="button" runat="server" Text="Previous" CommandName="Previous" OnClick="linkPrevious_Click"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&lt;br /&gt;     &amp;lt;/td&amp;gt;&lt;br /&gt;     &amp;lt;td&amp;gt;&lt;br /&gt;         &amp;lt;asp:Literal ID="litPageCount" runat="server"&amp;gt;&amp;lt;/asp:Literal&amp;gt;&lt;br /&gt;         &amp;lt;span id="spanGotpPage" runat="server"&amp;gt;Goto Page:&lt;br /&gt;             &amp;lt;asp:TextBox Width="15" ID="txtPageNo" CssClass="inputfld" runat="server" MaxLength="3"&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;             &amp;lt;asp:Button ID="btnGo" runat="server" Text="Go" CssClass="button" OnClick="btnGo_Click" /&amp;gt;&lt;br /&gt;         &amp;lt;/span&amp;gt;&lt;br /&gt;     &amp;lt;/td&amp;gt;&lt;br /&gt;     &amp;lt;td&amp;gt;&lt;br /&gt;         &amp;lt;asp:LinkButton ID="linkNext" CssClass="button" runat="server" Text="Next" CommandName="Next" OnClick="linkNext_Click"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&lt;br /&gt;     &amp;lt;/td&amp;gt;&lt;br /&gt; &amp;lt;/tr&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;.Cs Page Coding:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;void Controls_Paging_PreRender(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    litPageCount.Text = string.Format("{0} of {1} Pages  ", SelectedPageIndex + 1, TotalNoOfPages);&lt;br /&gt;    if (SelectedPageIndex == TotalNoOfPages - 1)&lt;br /&gt;    {&lt;br /&gt;        linkNext.Enabled = false;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        linkNext.Enabled = true;&lt;br /&gt;    }&lt;br /&gt;    if (SelectedPageIndex == 0)&lt;br /&gt;    {&lt;br /&gt;        linkPrevious.Enabled = false;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        linkPrevious.Enabled = true;&lt;br /&gt;    }&lt;br /&gt;    txtPageNo.Text = (SelectedPageIndex + 1).ToString();&lt;br /&gt;}&lt;br /&gt;protected void btnGo_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        int newPageIndex = 0;&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            newPageIndex = Convert.ToInt32(txtPageNo.Text) - 1;&lt;br /&gt;            if (newPageIndex &gt; TotalNoOfPages - 1)&lt;br /&gt;            {&lt;br /&gt;                newPageIndex = TotalNoOfPages - 1;&lt;br /&gt;            }&lt;br /&gt;            if (newPageIndex &lt; 0)&lt;br /&gt;            {&lt;br /&gt;                newPageIndex = 0;&lt;br /&gt;            }&lt;br /&gt;            SelectedPageIndex = newPageIndex;&lt;br /&gt;            PageIndexChanging(btnGo, new GridViewPageEventArgs(newPageIndex));&lt;br /&gt;        }&lt;br /&gt;        catch { }&lt;br /&gt;    }&lt;br /&gt;public event GridViewPageEventHandler PageIndexChanging;&lt;br /&gt;    public int PageSize&lt;br /&gt;    {&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            ViewState["PageSize"] = value;&lt;br /&gt;        }&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            if (ViewState["PageSize"] is int)&lt;br /&gt;                return (int)ViewState["PageSize"];&lt;br /&gt;            else return 0;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int CurrentPageIndex&lt;br /&gt;    {&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            ViewState["CurrentPageIndex"] = value;&lt;br /&gt;        }&lt;br /&gt;        private get&lt;br /&gt;        {&lt;br /&gt;            if (ViewState["CurrentPageIndex"] is int)&lt;br /&gt;                return (int)ViewState["CurrentPageIndex"];&lt;br /&gt;            else return 0;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public int StartIndex&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return SelectedPageIndex * PageSize;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int TotalNoOfPages&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return (int)Math.Ceiling(TotalNoOfRows / (float)PageSize);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public long TotalNoOfRows&lt;br /&gt;    {&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            ViewState["TotalNoOfRows"] = value;&lt;br /&gt;        }&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            if (ViewState["TotalNoOfRows"] is long)&lt;br /&gt;                return (long)ViewState["TotalNoOfRows"];&lt;br /&gt;            else return 0;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public int SelectedPageIndex&lt;br /&gt;    {&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            ViewState["SelectedPageIndex"] = value;&lt;br /&gt;        }&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            if (ViewState["SelectedPageIndex"] is int)&lt;br /&gt;                return (int)ViewState["SelectedPageIndex"];&lt;br /&gt;            else return 0;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    protected void linkNext_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (SelectedPageIndex &lt; TotalNoOfPages)&lt;br /&gt;        {&lt;br /&gt;            SelectedPageIndex = SelectedPageIndex + 1;&lt;br /&gt;            PageIndexChanging(sender, new GridViewPageEventArgs(SelectedPageIndex));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    protected void linkPrevious_Click(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (SelectedPageIndex &gt; 0)&lt;br /&gt;        {&lt;br /&gt;            SelectedPageIndex = SelectedPageIndex - 1;&lt;br /&gt;            PageIndexChanging(sender, new GridViewPageEventArgs(SelectedPageIndex));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The page where the control is used&lt;br /&gt;&lt;cous:paging id="pagingDL" runat="server" currentpageindex="0" pagesize="8"&gt;&lt;/cous:paging&gt;&lt;br /&gt;Here the page size is initialized.  From the cs page call the bind datalist function as&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;void bindDataList()&lt;br /&gt;{&lt;br /&gt;    long totalNoOfRows;&lt;br /&gt;    ImageTblMasterTable dtImage = ImageTblMaster.SelectAll(-1, 1, pagingDL.StartIndex, pagingDL.PageSize, out totalNoOfRows);&lt;br /&gt;    pagingDL.TotalNoOfRows = totalNoOfRows;&lt;br /&gt;    dlImage.DataSource = dtImage;&lt;br /&gt;    dlImage.DataBind();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here i am using custom paging. So i am sending the page start index and page size which is converted to ennIndex before the call to SP. Here is code from SP&lt;br /&gt;&lt;per&gt;&lt;code&gt;&lt;br /&gt;Select @TotalNoOfRows = Count(*) FROM [dbo].[Image_tbl_Master]&lt;br /&gt;&lt;br /&gt;Select * from&lt;br /&gt;(&lt;br /&gt;SELECT ROW_NUMBER() OVER (ORDER BY ImageId) as RowNumber, m.* FROM [dbo].[Image_tbl_Master] as m&lt;br /&gt;)t Where&lt;br /&gt;RowNumber &gt;= @StartIndex&lt;br /&gt;AND&lt;br /&gt;RowNumber &lt;= @EndIndex As i am using SQL Server 2005 i get the facility of ROW_Number() but in SQL Server 2000 or before, there is no row number. So you have to change the query like Select * from ( Select (Select Count(*) from Image_tbl_Master where ImageId&lt;=img.ImageId )as RowNumber, img.* from Image_tbl_Master as img )t  Where RowNumber &gt;= @StartIndex&lt;br /&gt;AND&lt;br /&gt;RowNumber &lt;= @EndIndex &lt;/code&gt;&lt;br /&gt;Here row number is calculated on the fly through a subquery. See the where clause "ImageId&lt;=img.ImageId ", it is responsible for the sorting. As i was sorting with ImageId i have used it like that.&lt;/per&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-1225189609987624562?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/1225189609987624562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=1225189609987624562' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1225189609987624562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1225189609987624562'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/02/paging-in-datalist-and-repeater.html' title='Paging in Datalist and Repeater'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_7BJz2MaZ-L0/SZ6g3N_q8YI/AAAAAAAAAM8/glECEOP-OsM/s72-c/Paging.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-3384700549938833386</id><published>2009-01-13T14:31:00.006+05:30</published><updated>2009-04-07T20:26:42.638+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Add Row'/><category scheme='http://www.blogger.com/atom/ns#' term='GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Add / Insert a row to a gridview</title><content type='html'>In many cases we come across the situation where we have to add a row to a gridview. We can create a new grid view row through the GridViewRow class. But there is no property/method to a grid to add the row to the gridview. Not even the Gridview.Rows property has any methor to add/insert a row.&lt;br /&gt;In a situation i had to add a footer to show the total of the fields displayed in the gridview. I knew that i could set the value in footer through RowDataBound event of GV by inspection like&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;if(e.Row.RowType==DataControlRowType.Footer)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;here e is the GridViewRowEventArgs parameter to the event.&lt;br /&gt;But i was looking for something new. I found i can create the row through GridViewRow which takes the rowindex, rowtype ...  parameters.&lt;br /&gt;Then i found i can cast the parent of any row of gridview to a table but cannot cast the gridview directly to table. So here is how i implemented...&lt;br /&gt;::::::::::::::::::::::::::::::::::::::::::::::::::::::&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;gvTaxPlanning.DataSource = dv;&lt;br /&gt;         gvTaxPlanning.DataBind();&lt;br /&gt;if (gvTaxPlanning.Rows.Count &gt; 0)&lt;br /&gt;         {&lt;br /&gt;             GridViewRow gvr = new GridViewRow(gvTaxPlanning.Rows.Count, gvTaxPlanning.Rows.Count, DataControlRowType.Footer, DataControlRowState.Normal);&lt;br /&gt;             TableCell tc = new TableCell();&lt;br /&gt;             tc.Text = "Total";&lt;br /&gt;             gvr.Cells.Add(tc);&lt;br /&gt;             tc = new TableCell();&lt;br /&gt;             tc.Text = (tEQTax + tMFTax + tULTax + tBulTax + tBankTax + tAssetTax).ToString(GlobalSettings.FloatNumberFormatter);&lt;br /&gt;             gvr.Cells.Add(tc);&lt;br /&gt;             gvr.Font.Bold = true;&lt;br /&gt;             gvr.BackColor = System.Drawing.ColorTranslator.FromHtml("#000084");&lt;br /&gt;             gvr.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");&lt;br /&gt;             Table tab = (Table)gvTaxPlanning.Rows[0].Parent;&lt;br /&gt;             tab.Rows.Add(gvr);            &lt;br /&gt;         }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I thought that it will need the&lt;br /&gt;gridView.ShowFooter = true; to show the new row i have added as it was footer and by default grid doesn't show the footer.&lt;br /&gt;But not... it ws showing the footer whithout setting it to true...&lt;br /&gt;And one more thing... The RowCreated event is not fired when you add this new row.&lt;br /&gt;&lt;br /&gt;Read More &lt;a href="http://blog.falafel.com/2007/04/12/DynamicallyAddRowsToAGridView.aspx"&gt;http://blog.falafel.com/2007/04/12/DynamicallyAddRowsToAGridView.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-3384700549938833386?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/3384700549938833386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=3384700549938833386' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3384700549938833386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3384700549938833386'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2009/01/adding-row-to-gridview.html' title='Add / Insert a row to a gridview'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-827120922112630239</id><published>2008-12-31T20:25:00.004+05:30</published><updated>2009-04-07T20:28:01.036+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Databind'/><category scheme='http://www.blogger.com/atom/ns#' term='paging'/><category scheme='http://www.blogger.com/atom/ns#' term='GridView'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='sorting'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Paging,Sorting in datagrid</title><content type='html'>Paging and sorting is the most common feature of datagrid. As i am very much used to with ObjectDataSource, i don't have to do anything for implementing Paging and sorting.&lt;br /&gt;Just set the datasource of the gridview to the ObjectDataSource and&lt;br /&gt;set the AllowPaging and AllowSorting property of the grid view to true and&lt;br /&gt;for each column put some SortExpression and&lt;br /&gt;some pagesize for the gridview.&lt;br /&gt;And thats all for implementing the paging and sorting. ObjectDataSource  will take care of the remainings for you.&lt;br /&gt;But some situalition arises where i must not use ObjectDataSource, actuaaly not using ObjectDataSource  is easier from coding perspective though we have to implement the paging and sorting explicitly. So i used this code, a overloaded version of bindGrid() function to handle the situaltion&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;protected override void OnInit(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      base.OnInit(e);&lt;br /&gt;      gvStockCode.Sorting += new GridViewSortEventHandler(gvStockCode_Sorting);&lt;br /&gt;      gvStockCode.PageIndexChanging += new GridViewPageEventHandler(gvStockCode_PageIndexChanging);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void gvStockCode_PageIndexChanging(object sender, GridViewPageEventArgs e)&lt;br /&gt;  {&lt;br /&gt;      gvStockCode.PageIndex = e.NewPageIndex;&lt;br /&gt;      bindGrid(); &lt;span style="color: rgb(0, 153, 0);"&gt;//Call bindgrid without any parameter so that previous sorting is maintained&lt;/span&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void gvStockCode_Sorting(object sender, GridViewSortEventArgs e)&lt;br /&gt;  {&lt;br /&gt;      gvStockCode.PageIndex = 0; &lt;span style="color: rgb(0, 153, 0);"&gt;//Don't change page index if you want to show the old page the user was&lt;/span&gt;&lt;br /&gt;      if (ViewState["SortDirection"] != null &amp;amp;&amp;amp; ViewState["SortExpression"] != null)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            SortDirection direction = (SortDirection)ViewState["SortDirection"];&lt;br /&gt;            string sortExpr = ViewState["SortExpression"].ToString();&lt;br /&gt;            if (sortExpr.ToLower() == e.SortExpression.ToLower())&lt;br /&gt;            {&lt;br /&gt;                direction = direction == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;&lt;br /&gt;            }&lt;br /&gt;            bindGrid(e.SortExpression, direction);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            bindGrid(e.SortExpression, e.SortDirection);&lt;br /&gt;        }&lt;br /&gt;  }&lt;br /&gt;  protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;  {&lt;br /&gt;If(!IsPostBack)&lt;br /&gt;      bindGrid();&lt;br /&gt;  }&lt;br /&gt;void bindGrid()&lt;br /&gt;  {&lt;br /&gt;      SortDirection direction = SortDirection.Ascending;&lt;span style="color: rgb(0, 102, 0);"&gt; //Default Sort Direction&lt;/span&gt;&lt;br /&gt;      string sortExpr = ""; &lt;span style="color: rgb(0, 102, 0);"&gt;//Default sort expression, you can put any expression if wanted to be default for grid&lt;/span&gt;&lt;br /&gt;      if (ViewState["SortDirection"] != null &amp;amp;&amp;amp; ViewState["SortExpression"] != null)&lt;br /&gt;      {&lt;br /&gt;          direction = (SortDirection)ViewState["SortDirection"];&lt;br /&gt;          sortExpr = ViewState["SortExpression"].ToString();&lt;br /&gt;      }&lt;br /&gt;      bindGrid(sortExpr, direction);&lt;br /&gt;  }&lt;br /&gt;  void bindGrid(string sortExpression, SortDirection sortDirection)&lt;br /&gt;  {&lt;br /&gt;      DataTable dt = BusinessLogic.FillTable();&lt;span style="color: rgb(0, 153, 0);"&gt;//Some function declared in BL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      DataView dv = new DataView(dt);&lt;br /&gt;      if (sortExpression != string.Empty)&lt;br /&gt;      {&lt;br /&gt;          if (sortDirection == SortDirection.Ascending)&lt;br /&gt;              dv.Sort = sortExpression + " ASC";&lt;br /&gt;          else&lt;br /&gt;              dv.Sort = sortExpression + " DESC";&lt;br /&gt;      }&lt;br /&gt;      gvStockCode.DataSource = dv;&lt;br /&gt;      gvStockCode.DataBind();&lt;br /&gt;      ViewState["SortExpression"] = sortExpression;&lt;br /&gt;      ViewState["SortDirection"] = sortDirection;&lt;br /&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-827120922112630239?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/827120922112630239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=827120922112630239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/827120922112630239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/827120922112630239'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/12/pagingsorting-in-datagrid.html' title='Paging,Sorting in datagrid'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-5271777809780646912</id><published>2008-10-30T17:51:00.001+05:30</published><updated>2008-10-30T17:56:24.722+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='validator'/><category scheme='http://www.blogger.com/atom/ns#' term='VB.net'/><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='validation'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Trigger validator control validation from javascript</title><content type='html'>function checkForConfirmRate()&lt;br /&gt;    {&lt;br /&gt;        for(var i=0;i&amp;lt;Page_Validators.length;i++)&lt;br /&gt;        {&lt;br /&gt;            if(Page_Validators[i].id != '&amp;lt;%= rfvStockCode.ClientID %&amp;gt;')&lt;br /&gt;            {&lt;br /&gt;                continue;&lt;br /&gt;            }&lt;br /&gt;            ValidatorValidate(Page_Validators[i]); //Function to trigger the validation&lt;br /&gt;            ValidatorUpdateIsValid();//To show the validation message according to the validator display property&lt;br /&gt;            ValidationSummaryOnSubmit();//To show in sumary(if exists)&lt;br /&gt;            return Page_IsValid;&lt;br /&gt;        }        &lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-5271777809780646912?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/5271777809780646912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=5271777809780646912' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/5271777809780646912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/5271777809780646912'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/10/trigger-validator-control-validation.html' title='Trigger validator control validation from javascript'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-6758987018168557641</id><published>2008-09-18T18:58:00.005+05:30</published><updated>2009-04-07T20:25:17.433+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Aggregate Function'/><category scheme='http://www.blogger.com/atom/ns#' term='Max'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Ado.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Column'/><category scheme='http://www.blogger.com/atom/ns#' term='Datatable'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net 2.0'/><title type='text'>Run aggregate on datatable column</title><content type='html'>I had one table with columns "Name" and "Department" which i need to display in a multiline textbox. like below&lt;br /&gt;Name~~~~~~~~ Dept&lt;br /&gt;Tarun Ghosh~~~SWD&lt;br /&gt;Diptangshu Das~SSWD&lt;br /&gt;So that the names and Dept are aligned properly. So i needed the Max of the string length of the column "Name" and give a right-padding to name to make all of same length with the maximum lengthed name.&lt;br /&gt;Firstly i went with the primitive looping through each record and calculate the max of the row, if it is greater than the global max, set global max to current max algo...&lt;br /&gt;But i was not satisfied with the approach even though no problem.&lt;br /&gt;Then i got the&lt;br /&gt;&lt;pre class="libCScode" id="ctl00_rs1_mainContentContainer_ctl21CSharp" space="preserve"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; Object Compute(&lt;br /&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; expression,&lt;br /&gt; &lt;span style="color:blue;"&gt;string&lt;/span&gt; filter&lt;br /&gt;)&lt;br /&gt;&lt;/pre&gt; function of DataTable. Expression par needs to be some aggregate function lik Sum, Avg,Min,Max,Count,Var. with filter expression is same as where clause in dt.Select() function.&lt;br /&gt;But one problemmmmmmmm.... The expression parameter can't work on computed column. Like say you have two column qty and unit price. You need to get the max(qty*unitPrice), then first you have to add a new column to hold the value of the multiplied result and then use the compute function on that column.&lt;br /&gt;So in my case i wanted to get the max of length. So i added a column as&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;           DataColumn col = new DataColumn("Length");&lt;br /&gt;           col.Expression = "Len(Name)";&lt;br /&gt;           col.DataType = typeof(int);&lt;br /&gt;           dt.Columns.Add(col);&lt;br /&gt;           object obj= dt.Compute("Max(Length)","");&lt;br /&gt;           Response.Write(obj.ToString());&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;obj is storing the max length value&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Some useful link&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/lcamlibel/DataTableComputeLC11302005060506AM/DataTableComputeLC.aspx"&gt;Link1&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx"&gt;Link2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-6758987018168557641?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/6758987018168557641/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=6758987018168557641' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6758987018168557641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6758987018168557641'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/09/run-aggregate-on-datatable-column.html' title='Run aggregate on datatable column'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-164141974500732349</id><published>2008-09-17T13:03:00.005+05:30</published><updated>2008-09-17T13:18:44.171+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Age on Today'/><category scheme='http://www.blogger.com/atom/ns#' term='GetDate'/><category scheme='http://www.blogger.com/atom/ns#' term='Date Difference'/><category scheme='http://www.blogger.com/atom/ns#' term='DateDiff'/><category scheme='http://www.blogger.com/atom/ns#' term='Age Calculation'/><category scheme='http://www.blogger.com/atom/ns#' term='Age'/><title type='text'>Get the date diference in the form of x Years y months z days</title><content type='html'>Somethimes we need to get the difference of two dates in SQL server to send the result to front end. The result of DateDiff SQL function will give the difference of the date for a particular part like year or  month or day... If you think of just concatinating the results got from three datediff function with parameters for year,month and day, you will get the wrong result. WHY???&lt;br /&gt;DateDiff(Year,'2007/31/12','2008/1/1') is 1 though the difference only 1 day.&lt;br /&gt;Similarly month differnce and day difference will be shown as 1.&lt;br /&gt;So the result age is "1 year 1 month 1 day". But actyually only "1 day".&lt;br /&gt;Here is a function i wrote to get the exact value. This is very useful when you need to get the age on today when you have DOB stored in your database. Here you have to send the DOB as @startdate and GetDate() as @endDate&lt;br /&gt;&lt;br /&gt;Create FUNCTION [dbo].[fn_GetDateDifference] (@startDate as DateTime,@endDate DateTime)&lt;br /&gt;RETURNS varchar(50)  AS &lt;br /&gt;BEGIN&lt;br /&gt; DECLARE @res varchar(50)&lt;br /&gt; DECLARE @mon int,@year int,@day int&lt;br /&gt; SELECT @year = DateDiff(year,@startDate,@endDate)&lt;br /&gt; --SET @year = @day/365&lt;br /&gt; SET @startDate = DateAdd(Year,@Year,@startDate)&lt;br /&gt; if(@startDate &gt; @endDate) --If the month value of Start Date is more than that of End Date&lt;br /&gt;--@startDate can become more than date 2 if the values are like&lt;br /&gt;--@startDate = '2007/12/15' and @endDate = '2008/02/01',&lt;br /&gt;--The datediff year will be 1 though only 2 month+ difference&lt;br /&gt; BEGIN&lt;br /&gt;  SET @year = @year - 1&lt;br /&gt;  SET @startDate = DateAdd(Year,-1,@startDate)&lt;br /&gt; END&lt;br /&gt; SELECT @mon = DateDiff(Month,@startDate,@endDate)&lt;br /&gt; --SET @mon = @day/28&lt;br /&gt; --Select @mon = DateDiff(Month,@startDate,@endDate)&lt;br /&gt; SET @startDate = DateAdd(Month,@mon,@startDate)&lt;br /&gt; if(@startDate &gt; @endDate)&lt;br /&gt;--Same as year,month can show maximum of 1 unit more if the start date "Day" val in more than end date "Day value"&lt;br /&gt; BEGIN&lt;br /&gt;  set @startDate = DateAdd(Month,-1,@startDate)&lt;br /&gt;  set @mon = @mon - 1&lt;br /&gt; END&lt;br /&gt; SELECT @day = DateDiff(Day,@startDate,@endDate)&lt;br /&gt; set @res = ''&lt;br /&gt; If(@year &gt; 0)&lt;br /&gt;  SELECT @res = Cast(@year as Varchar(10)) + ' Year(s) '&lt;br /&gt; if( @year&gt;0 or @mon&gt;0)&lt;br /&gt;  Set @res = @res + Cast(@mon as Varchar(10)) + ' Month(s) '&lt;br /&gt; &lt;br /&gt; set @res = @res + Cast(@day as Varchar(10)) + ' Day(s)'&lt;br /&gt; --set @res = @year  &amp;amp; ' '&lt;br /&gt; --select @res = @year &amp;amp; ' ' &amp;amp; @mon  &amp;amp; ' ' &amp;amp;@day&lt;br /&gt; RETURN @res&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;Note: It is not a good practice to use backend sqlserver for this kind of calculations. It is preferable to return two dates to front end and then do the desired calculations.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-164141974500732349?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/164141974500732349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=164141974500732349' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/164141974500732349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/164141974500732349'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/09/get-date-diference-in-form-of-x-years-y.html' title='Get the date diference in the form of x Years y months z days'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-6270881966999025577</id><published>2008-07-14T18:34:00.006+05:30</published><updated>2008-07-14T19:24:18.186+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Generate RDL'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Dynamic Report'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service Web Service'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service'/><category scheme='http://www.blogger.com/atom/ns#' term='Drill Down Report'/><title type='text'>Generate Your Dynamic Report Through Reporting Service</title><content type='html'>I have posted some articles on reporting service. Here is a sample project which will generate report dynamically. It is having an interface where you select the database in a DDL then a table or view from the selected DB and select some columns for details and group of the report. Then it will generate the report RDL and publish it to your report server. If you want to select from multiple tables with joining, you can do that also by giving your custom query.&lt;br /&gt;Here are some setting which you will have to change to run the project like&lt;br /&gt;string serverName = "localhost";   //The server where the report will be published.&lt;br /&gt;string reportVirtualPath = "LocalReportServer"; //The virual directory path of the reportserver&lt;br /&gt;string parentFolder = "QuoteReports"; //The folder where the reports will be published.&lt;br /&gt;Here i am using some AppSettings val in web.config. Change those according your local settings. But in "MasterConStr" the 'Initial Catalog' value should be 'master' because this connection string is used for fetching data about DBs.&lt;br /&gt;Add the web reference of the reporting service to your ptoject. You may have to change the "RSLocal.ReportService2005" AppSettings value.&lt;br /&gt;Here is the link of the project&lt;a style="font-weight: bold; color: rgb(204, 0, 0);" href="http://w17.easy-share.com/1700907813.html"&gt;&lt;span&gt; &lt;/span&gt;&lt;span style="color: rgb(204, 0, 0);font-size:100%;" &gt;http://w17.easy-share.com/1700907813.html&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;Here i am using sql express repoting service and my report server and database is in dame machine. If you have the Report server installed in other machine than the Database you may have some problem with the DataSource. For that pls refer to my other post&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;&lt;a style="font-weight: bold;" href="http://aspxdev.blogspot.com/2008/06/use-stored-credential-for-report.html"&gt;Use stored credential for report created by c# code&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-6270881966999025577?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/6270881966999025577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=6270881966999025577' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6270881966999025577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6270881966999025577'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/07/generate-your-dynamic-report-through.html' title='Generate Your Dynamic Report Through Reporting Service'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-8153033677770544630</id><published>2008-07-08T22:29:00.006+05:30</published><updated>2008-07-22T13:12:25.053+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='PageRequestManager'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Balk Data'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Update Panel'/><title type='text'>Use PageRequestManager To Trigger Javascript for Asynchronous Postback</title><content type='html'>In my last post &lt;a href="http://aspxdev.blogspot.com/2008/07/send-balk-data-from-child-window-to.html"&gt;Send Balk Data(Datatable) From Child Window To Parent&lt;br /&gt;&lt;/a&gt; i explained how we can send bulk data from child window to parent. But if we are using Asp.Net ajax in client page i.e the postback is caused asynchronously, then we can't use the RegisterStartUpScript to call the javascript function. But instead we have to use the Microsoft's Ajax javascript framework. I did this with the use of PageRequestManager JS Class as follows&lt;br /&gt;&lt;br /&gt;var postBackThroughAdd  = false;&lt;br /&gt;function addRequestManager()&lt;br /&gt;{&lt;br /&gt;     var reqMgr=Sys.WebForms.PageRequestManager.getInstance();&lt;br /&gt;     reqMgr.add_beginRequest(&lt;br /&gt;         function()&lt;br /&gt;         {&lt;br /&gt;             //Do something before the call begins&lt;br /&gt;         }&lt;br /&gt;     )&lt;br /&gt;     reqMgr.add_endRequest(&lt;br /&gt;     function(sender,args)&lt;br /&gt;         {           &lt;br /&gt;             if (args.get_error() == undefined)//Checks there is no error&lt;br /&gt;             {&lt;br /&gt;                 if(postBackThroughAdd)&lt;br /&gt;                 {&lt;br /&gt;                     postBackThroughAdd = false;&lt;br /&gt;                     addToQuote();&lt;br /&gt;//Function to trigger the parent postback and flag set and close the page&lt;br /&gt;                 }&lt;br /&gt;             }&lt;br /&gt;         }&lt;br /&gt;     )&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Variable postBackThroughAdd is a flag variable, which is set "true" when the button for which we want to send the data to parent is clicked. The code is like&lt;br /&gt;&lt;br /&gt;&amp;lt;asp:Button ID="btnAddPartNoToCatalog" runat="server" Text="Add" CssClass="formButton"OnCommand="btnAddPartNoToCatalog_Command" OnClientClick="postBackThroughAdd = true;"                                                         /&amp;gt;&lt;br /&gt;&lt;br /&gt;Here if any error occurs while setting the data in session through server event btnAddPartNoToCatalog_Command, i am simply throughing the error with some userfriendly message. The message will be shown in JS message box and args.get_error() will not be undefined. So the function addToquote() will not be called.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note: addRequestManager() function should be called on bodyload so that the JS events are registered before they fires actully. With the help of PageRequestManager class you can do some other tasks like showing some message in div after some action has succeeded of failed, show/hide loading... div without using UpdateProgress but same functionality(In the beginRequest handler, set the div's "display" property to "block" and int endRequest hander display to "none").&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-8153033677770544630?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/8153033677770544630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=8153033677770544630' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/8153033677770544630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/8153033677770544630'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/07/use-paherequestmanager-to-trigger.html' title='Use PageRequestManager To Trigger Javascript for Asynchronous Postback'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-4824310282859351573</id><published>2008-07-04T15:21:00.008+05:30</published><updated>2008-07-04T17:00:31.630+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Set'/><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Parent'/><category scheme='http://www.blogger.com/atom/ns#' term='Balk Data'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Child'/><category scheme='http://www.blogger.com/atom/ns#' term='Datatable'/><title type='text'>Send Balk Data(Datatable) From Child Window To Parent</title><content type='html'>Currently in one of my .aspx page i was selecting some information from a child window which is opened from a parent window. I opened the window like&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;window.open('PartNoLookup.aspx','PartNo','left=150, top=60,width=800,height=600, toolbar=no, status=1,scrollbars=yes,resizable=no,dependent=yes');&lt;/span&gt;&lt;br /&gt;Some PartNos with their information was selected by the child "PartNoLookup.aspx" page. Now i have to send the part nos to the parent page to be displayed. My parent page was NewQuote.aspx.&lt;br /&gt;Now the problem arises if it was a small value then i could do it with&lt;br /&gt;window.opener.document.getelementById('parentCtrlId').value='Some Value'&lt;br /&gt;But as it was a bulk datatable i can't send it like that.&lt;br /&gt;I stored the DataTable in Session["PartNo"] from the child page. And placed a hidden field "hidFlag" (not with runat='server'. this should be a html hiddenfield) in the Parent Page (i.e. NewQuote.aspx). And wrote some javascript with the Page.ClientScript.RegisterStartupScript like&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;Page.ClientScript.RegisterStartupScript(typeof(string), "", "refreshParentAndClose();", true);&lt;/span&gt;&lt;br /&gt;And inside childpage (PartNoLookup.aspx) i added the JS function refreshParentAndClose() as&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;function refreshParentAndClose()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      window.opener.document.getelementById('parentCtrlId').value='checksession'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      window.opener.document.forms[0].submit();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      window.close();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;So this function will set the flag in the parent a also submit the page.&lt;br /&gt;Here as the page is postback by some unconventional way, only the PageLoad,PreRender and some processing cycle events will fire in the parent. So i have to check for the flag inside tha Load() event. So i added the checking code in Page_LoadCode as&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;if(Request.Form["hidFlag"]!=null)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      string flag=Request.Form["hidFlag"];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      switch(flag)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;            case "checksession":&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;                        //Check the session and show inside the page.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;            break;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;      }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note:Put the hidden field as Html hidden, not with runat=server coz, if you set it server variable then change by the javascript will no be visible as it will be restored from the viewstate. y JavaScript we are changing the value not the stored value inside Encripted ViewState. Also if you use server Hidden field the clientid may not be same as server id. So setting it from child page will be problemetic (but not impossible).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-4824310282859351573?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/4824310282859351573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=4824310282859351573' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4824310282859351573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4824310282859351573'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/07/send-balk-data-from-child-window-to.html' title='Send Balk Data(Datatable) From Child Window To Parent'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-1314627515377546587</id><published>2008-06-11T15:48:00.011+05:30</published><updated>2008-06-11T18:26:47.597+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='width'/><category scheme='http://www.blogger.com/atom/ns#' term='Screen heinght'/><category scheme='http://www.blogger.com/atom/ns#' term='Resize window'/><category scheme='http://www.blogger.com/atom/ns#' term='Postion window'/><category scheme='http://www.blogger.com/atom/ns#' term='position popup'/><category scheme='http://www.blogger.com/atom/ns#' term='ResizeWindow'/><category scheme='http://www.blogger.com/atom/ns#' term='move'/><category scheme='http://www.blogger.com/atom/ns#' term='middle'/><category scheme='http://www.blogger.com/atom/ns#' term='centre'/><category scheme='http://www.blogger.com/atom/ns#' term='move popup'/><category scheme='http://www.blogger.com/atom/ns#' term='Popup'/><title type='text'>Resize and position Javascript popup</title><content type='html'>In many of my project i came across the situation where i had to open a popup with a particular size and position the popup in the middle of the window. I was sending the height and width parameter in the window.open() funtion parameter. But many times i had to add some extra controls in that page which needs the increase of the popup size. I was problemetic for me to goback to the parent page and find the javascript which is opening the popup and change.&lt;br /&gt;So i decided to control the size from the popup itself. And i used&lt;br /&gt;window.resizeTo(width,height) function for that purpose and called it on body onLoad event.&lt;br /&gt;But what about positioning the popup?&lt;br /&gt;For both the pubpose to solve i wrote a function resizeAndPositionWindow() which takes height and width as parameter and positions the popup in the middle of the window. Below is the function...&lt;br /&gt;&lt;div&gt;function resizeandPositionWindow(width,height)&lt;/div&gt;&lt;div&gt;{ &lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;window.resizeTo(width,height); &lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;var scrW = 1024, scrH = 768;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;var popW=width,popH=height;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;if (document.all document.layers) {&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 28px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;scrW = screen.availWidth;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 28px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;scrH = screen.availHeight; &lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;else&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;try&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;scrW = window.screen.availWidth;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;scrH = screen.availHeight;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;catch(e){}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;if(document.all)&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;popW=document.body.clientWidth;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;else &lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;if(document.layers)&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;popW=window.innerWidth;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;popH=window.innerHeight;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;else&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;try&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;{&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 64px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;popW=window.innerWidth;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 64px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;popH=window.innerHeight;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 48px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;catch(e){alert('Exception');}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 32px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;}&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 76px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;var x,y;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;x=(scrW-popW)/2-13;&lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;y=(scrH-popH)/2; &lt;/div&gt;&lt;div style="PADDING-RIGHT: 0px; PADDING-LEFT: 16px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px"&gt;window.moveTo(x,y);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;br /&gt;By default it is assumed that the screen resolution of the user is 1024X768. Then it determines the actual height.&lt;br /&gt;I used the above funtion to make a function which will take a int parameter as gap between the popup and computer screen and will make the popup which will have that length in top,bottom,left and right.&lt;br /&gt;function resizeAccordingToScreenSize(gap)&lt;br /&gt;{&lt;br /&gt;   var scrW = 1024, scrH = 768;&lt;br /&gt;   if (document.all document.layers) {&lt;br /&gt;   scrW = screen.availWidth;&lt;br /&gt;   scrH = screen.availHeight;&lt;br /&gt;   }&lt;br /&gt;    else&lt;br /&gt;   {&lt;br /&gt;      try&lt;br /&gt;      {&lt;br /&gt;         scrW = window.screen.availWidth;&lt;br /&gt;         scrH = screen.availHeight;&lt;br /&gt;      }&lt;br /&gt;      catch(e){}&lt;br /&gt;   }&lt;br /&gt;   var gapPx=0;&lt;br /&gt;   try&lt;br /&gt;   {&lt;br /&gt;      gapPx=parseInt(gap)*2;&lt;br /&gt;   }&lt;br /&gt;   catch(e){alert("Wrong value for gap.")}&lt;br /&gt;   resizeAndPositionWindow(scrW-gapPx,scrH-gapPx);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-1314627515377546587?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/1314627515377546587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=1314627515377546587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1314627515377546587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1314627515377546587'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/06/in-many-of-my-project-i-came-across.html' title='Resize and position Javascript popup'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-4096605499225441447</id><published>2008-06-03T14:29:00.012+05:30</published><updated>2008-07-14T19:26:20.428+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Shared Data Source'/><category scheme='http://www.blogger.com/atom/ns#' term='Generate RDL'/><category scheme='http://www.blogger.com/atom/ns#' term='Delpoy report'/><category scheme='http://www.blogger.com/atom/ns#' term='Report Specific Data Source'/><category scheme='http://www.blogger.com/atom/ns#' term='Dynamic Report'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service Web Service'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service'/><title type='text'>Use stored credential for report created by c# code</title><content type='html'>In my current project i have created an interface through which admin can generate the report he wants from any of the table (or combination of tables) from any DB in the server. The interface is generating the xml Report Defination (rdl) and publishing it with the reporting service web service.&lt;br /&gt;Now the problem came with the datasource of the report. When i publish the report it was showing the username and password input box in the report viewer. If i put those it was running beautifulluy. But it was not what i wanted. None of us will bother to give the UID and password everytime. Here is the sample of code i used to generate the report&lt;br /&gt;&lt;br /&gt;static int zIndex = 1;&lt;br /&gt;string serverName = "localhost";&lt;br /&gt;string reportVirtualPath = "LocalReportServer";&lt;br /&gt;string parentFolder = "QuoteReports";&lt;br /&gt;string dataSetName = "DSSOP";&lt;br /&gt;string dataSourceName = "DynamicDataSource";&lt;br /&gt;string parTabName = "bodyTable";&lt;br /&gt;&lt;br /&gt;void deployReport(string reportName, string reportDefination)// reportDefination is the xml rdl&lt;br /&gt;{&lt;br /&gt;ReportingService2005 rs = new ReportingService2005();&lt;br /&gt;rs.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;byte[] byteRDL;&lt;br /&gt;System.Text.UTF8Encoding encoder = new UTF8Encoding();&lt;br /&gt;byteRDL = encoder.GetBytes(reportDefination);&lt;br /&gt;Property[] rsProperty = new Property[10];&lt;br /&gt;//Property property = new Property();&lt;br /&gt;Warning[] warnings;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;warnings = rs.CreateReport(reportName, "/" + parentFolder, true, byteRDL, null);&lt;br /&gt;}&lt;br /&gt;catch (System.Web.Services.Protocols.SoapException ex)&lt;br /&gt;{&lt;br /&gt;tdMessage.InnerHtml = "&lt;span style="color:red;"&gt;Exception in publiching report.&lt;br /&gt;" + ex.Message + "&lt;/span&gt;";&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I was using report-specific datasource with authentication. My sample datasource section of the RDL is below&lt;br /&gt;&amp;lt;datasource name="Personal"&amp;gt;&lt;br /&gt;&amp;lt;?xml:namespace prefix = rd /&amp;gt;&amp;lt;rd:datasourceid&amp;gt;1a234378-11f1-4dc0-bc74-91df6d7d94f7&amp;lt;/rd:datasourceid&amp;gt;&lt;br /&gt;&amp;lt;connectionproperties&amp;gt;&lt;br /&gt;&amp;lt;dataprovider&amp;gt;SQL&amp;lt;/dataprovider&amp;gt;&lt;br /&gt;&amp;lt;connectstring&amp;gt;Data Source=SODC42\SQLEXPRESS;Initial Catalog=SOP;UID=sa;password=123456;&amp;lt;/connectstring&amp;gt;&lt;br /&gt;&amp;lt;/connectionproperties&amp;gt;&lt;br /&gt;&amp;lt;/datasource&amp;gt;&lt;br /&gt;&lt;br /&gt;Though i was putting the connection string with UID and password, still it was showing the textboxes for username and password.&lt;br /&gt;After a lot of google i found that reporting service uses two connection strings 1) one for connection to the report server 2) another for connection the report server to the databse (In mycase the both of report server and DB server is same express version in localhost). The connection string supplied in the RDL is for the first purpose and the second connection information is stored with the DataSource information in the ReportServer DB.&lt;br /&gt;Then i open the report with the reportmanager (&lt;a href="http://localhost/reports"&gt;http://localhost/reports&lt;/a&gt;) and edit the report. In the editor i found the datasources link where i saw the "Credentials supplied by the user running the report" radio is selected. I canged the selection to "Credentials stored securely in the report server" and gave the desired credentials. Then i saw the report is not showinf the text boxes.&lt;br /&gt;Now it was clear that the problem is with the DataSource not with the RDL. Then i went with the idea of using SharedDataSource and attach it with the report. While deploying the report i was checking if the shared datasource is already existing. If not then create it. Here is the code for creating the shared datasource.&lt;br /&gt;&lt;br /&gt;DataSourceDefinition def = new DataSourceDefinition();&lt;br /&gt;def.CredentialRetrieval = CredentialRetrievalEnum.Store;&lt;br /&gt;def.ConnectString = ReportConnection.GetConnection("SOP").ConnectionString;&lt;br /&gt;def.Enabled = true;&lt;br /&gt;def.EnabledSpecified = true;&lt;br /&gt;def.Extension = "SQL";&lt;br /&gt;def.ImpersonateUser = false;&lt;br /&gt;def.ImpersonateUserSpecified = true;&lt;br /&gt;def.WindowsCredentials = false;&lt;br /&gt;def.UserName = "sa";&lt;br /&gt;def.Password = "123456";&lt;br /&gt;rs.CreateDataSource(dataSourceName, dataSourcePath, true, def, null);&lt;br /&gt;rs.SetDataSourceContents(dataSourcePath + "/" + dataSourceName, def);&lt;br /&gt;&lt;br /&gt;Note:Before creating you have to check whether it already exists of not. And also the folder structure.&lt;br /&gt;The rdl for datasource :&lt;br /&gt;&amp;lt;DataSources&amp;gt;&lt;br /&gt;&amp;lt;DataSource Name="DynamicDataSource"&amp;gt;&lt;br /&gt;&amp;lt;DataSourceReference&amp;gt;/Data Sources/DynamicDataSource&amp;lt;/DataSourceReference&amp;gt;&lt;br /&gt;&amp;lt;/DataSource&amp;gt;&lt;br /&gt;&amp;lt;/DataSources&amp;gt;&lt;br /&gt;Now the report is running fine.&lt;br /&gt;But still there was something hitting in my mind. Why i shall use SharedDataSource? I shall use report specific datasource. But how?&lt;br /&gt;After some days lots of RnD s i found it. It is totally my assumtion. I have no idea how far it is true. But it works.&lt;br /&gt;&lt;strong&gt;The report specific datasources you have to keep in a folder "Data Sources" in the same directory as the report and then only the report can use it. So i created the datasource in the report folder's "Data Sources" folder. And so far it is running.&lt;br /&gt;&lt;br /&gt;&lt;a style="color: rgb(204, 0, 0);" href="http://w17.easy-share.com/1700907813.html"&gt;Download Sample Project&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: normal;"&gt;For information about the project refer to my other post&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;a style="font-weight: bold; color: rgb(204, 0, 0);" href="http://aspxdev.blogspot.com/2008/07/generate-your-dynamic-report-through.html"&gt;Generate Your Dynamic Report Through Reporting Service&lt;/a&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-4096605499225441447?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/4096605499225441447/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=4096605499225441447' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4096605499225441447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4096605499225441447'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/06/use-stored-credential-for-report.html' title='Use stored credential for report created by c# code'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-7184233485511049917</id><published>2008-05-29T15:41:00.008+05:30</published><updated>2008-05-29T16:18:03.467+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='InitialToogleState'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Collapse Group'/><category scheme='http://www.blogger.com/atom/ns#' term='Toogle Group'/><category scheme='http://www.blogger.com/atom/ns#' term='Initial Visibility'/><category scheme='http://www.blogger.com/atom/ns#' term='expand with query string'/><category scheme='http://www.blogger.com/atom/ns#' term='Expand Group'/><category scheme='http://www.blogger.com/atom/ns#' term='Expand'/><category scheme='http://www.blogger.com/atom/ns#' term='Dynamic Toogle'/><category scheme='http://www.blogger.com/atom/ns#' term='Parameter'/><category scheme='http://www.blogger.com/atom/ns#' term='Reporting Service'/><category scheme='http://www.blogger.com/atom/ns#' term='Drill Down Report'/><title type='text'>Reporting service: Dynamic Toggle Group</title><content type='html'>In my current project i have to use Reporting Service 2005 for generating some reports. It was the first time for me to RS. The report was showing some group on Year &gt;&gt; Month &gt;&gt; Day. The report was drill down one. I had to show the current month's days open i.e when the user open the report which is decending sorted with year,month,day will show the report with current mont's days expanded. All other years and month will remain collapsed.&lt;br /&gt;For that i added two parameter to my report through&lt;br /&gt;Report Layout (Designer)-&gt; Report (Menu) -&gt; Report Parameters(sub menu).&lt;br /&gt;The parameters are showYear of type int and showMonth of type int.&lt;br /&gt;Default value for showYear, i selected "non-queried" and in the textbox wrote =Year(Today)&lt;br /&gt;and same for showMonth with TB value =Month(Today) so that the default value is set to the current month and year.&lt;br /&gt;Now i edit the group showing the month and in the visibility tab i set &lt;span style="color:#000099;"&gt;"Initial Visibility"&lt;/span&gt; expression to "=IIF(Parameters!showYear.Value=Fields!Year.Value,false,true)", so that if the yeay is equals to current year then it will stay initially visible. And for day i set expression to "=IIF(Parameters!showYear.Value=Fields!Year.Value,IIF(Parameters!showMonth.Value=Fields!Month.Value, false,true),false)", so that if the month and year is euals to current then it will be stay initially visible (i kept the "Visibility can be toogled by another report item" section as it was.).&lt;br /&gt;Now when i preview the report i found everything is running fine. By default it is expanding current year and month and if i put some other value in the report changing textbox it is expanding corresponding record. But the "+" and "-" signgs for toogle for those initially expanded is showing opposite i.e. "+" even when initially it is expanded and "-" when clicked to collapse.&lt;br /&gt;Why this is happening? After searching various properies for the report and its item i got the "&lt;span style="color:#000099;"&gt;InitialToogleState&lt;/span&gt;" property of the textbox which by default is collapsed. Then i set this property to expression so that it is "Collapsed" and "Expanded" properly to show "+" and "-" sign respectively.&lt;br /&gt;I set the year textbox's (TB which is responsible for toggle in year group row) InitialToogleState property to "=IIF(Parameters!showYear.Value=Fields!Year.Value,true,false)" and for month's one "=IIF(Parameters!showYear.Value=Fields!Year.Value,IIF(Parameters!showMonth.Value=Fields!Month.Value, true,false),true)" . Then i saw the result was as desired.&lt;br /&gt;We can hide the Parameter Promt in the report viewer by ShowParameterPrompts="False" in the reportviewer control and send the parameter by querystring as 'showYear=2004&amp;amp;showMonth=5' .&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;Some points to note:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;1) "InitialToogleState" property is boolean. "Collapsed" indicates false and "Expanded" true&lt;br /&gt;2) "Initial Visibility" is set to month and day rows where as "InitialToogleState" is set for year and month TB.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;One useful link:&lt;a href="http://msdn.microsoft.com/en-us/library/aa337391.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa337391.aspx&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-7184233485511049917?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/7184233485511049917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=7184233485511049917' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7184233485511049917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/7184233485511049917'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/05/reporting-service-dynamic-toggle-group.html' title='Reporting service: Dynamic Toggle Group'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-6738819825511217084</id><published>2008-05-21T19:54:00.004+05:30</published><updated>2008-05-29T20:06:19.508+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XmlWriter'/><category scheme='http://www.blogger.com/atom/ns#' term='XML Encoding Problem'/><category scheme='http://www.blogger.com/atom/ns#' term='Xml Encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><category scheme='http://www.blogger.com/atom/ns#' term='Write XML Namespace'/><category scheme='http://www.blogger.com/atom/ns#' term='.Net'/><title type='text'>XML writing problem.. Encoding Fixing</title><content type='html'>MemoryStream ms = new MemoryStream();&lt;br /&gt;XmlTextWriter writer = new XmlTextWriter(ms, System.Text.ASCIIEncoding.UTF8);&lt;br /&gt;writer.Indentation = 3;&lt;br /&gt;writer.Formatting = Formatting.Indented;&lt;br /&gt;writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");&lt;br /&gt;writer.WriteStartElement("Report");&lt;br /&gt;writer.WriteAttributeString("xmlns", null, "http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition");&lt;span style="font-size:85%;color:#33cc00;"&gt;//Writing namespace&lt;/span&gt;&lt;br /&gt;writer.WriteAttributeString("xmlns", "rd", null, "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");&lt;span style="font-size:85%;color:#33cc00;"&gt;//Writing namespace&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Or You can use StringBuilder class object like below&lt;br /&gt;StringBuilder sb = new StringBuilder();&lt;br /&gt;StringWriter sw = new StringWriter(sb);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-6738819825511217084?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/6738819825511217084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=6738819825511217084' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6738819825511217084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6738819825511217084'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/05/xml-writing-problem-encoding-fixing.html' title='XML writing problem.. Encoding Fixing'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-8394017198234024280</id><published>2008-05-01T16:01:00.003+05:30</published><updated>2008-05-01T16:17:46.256+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='All Tables'/><category scheme='http://www.blogger.com/atom/ns#' term='Table Schema'/><category scheme='http://www.blogger.com/atom/ns#' term='Column Information'/><category scheme='http://www.blogger.com/atom/ns#' term='Database Information'/><category scheme='http://www.blogger.com/atom/ns#' term='All Column'/><category scheme='http://www.blogger.com/atom/ns#' term='Error sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Table Information'/><category scheme='http://www.blogger.com/atom/ns#' term='All Database'/><title type='text'>Some Handy SQL Server Query</title><content type='html'>&lt;strong&gt;&lt;span style="color:#3333ff;"&gt;Get the Information about all the databases available in your SQL Server&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;EXEC sp_databases&lt;br /&gt;EXEC sp_helpdb&lt;br /&gt;select * from master..sysdatabases&lt;br /&gt;SELECT * FROM sys.databases&lt;br /&gt;SELECT * FROM sys.sysdatabases&lt;br /&gt;EXEC sp_msForEachDB 'PRINT ''?'''&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#3333ff;"&gt;Get the Information about all the tables available in your SQL Server Database&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;SELECT     Owner = TABLE_SCHEMA,     TableName = TABLE_NAME FROM     INFORMATION_SCHEMA.TABLES WHERE     TABLE_TYPE = 'BASE TABLE'     AND OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'IsMsShipped') = 0 ORDER BY     TABLE_SCHEMA,     TABLE_NAME&lt;br /&gt;or&lt;br /&gt;exec sp_tables&lt;br /&gt;but with this you have to filter to exclude the table  owned by (&lt;br /&gt;TABLE_OWNER) 'sys','INFORMATION_SCHEMA'.&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#3333ff;"&gt;Get the Information about all the tables available in your SQL Server Database&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;sp_columns @tableName&lt;br /&gt;Select * from Information_Schema.Columns where Table_Name=@tableName&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-8394017198234024280?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/8394017198234024280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=8394017198234024280' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/8394017198234024280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/8394017198234024280'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/05/some-handy-sql-server-query.html' title='Some Handy SQL Server Query'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-727330398828605718</id><published>2008-04-16T23:01:00.003+05:30</published><updated>2008-04-16T23:25:14.735+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='ISNUMERIC'/><category scheme='http://www.blogger.com/atom/ns#' term='Cast'/><category scheme='http://www.blogger.com/atom/ns#' term='data type mix'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='ISNUMERIC PROBLEM'/><category scheme='http://www.blogger.com/atom/ns#' term='Error sql server'/><title type='text'>Problem Numeric check in SQL Server</title><content type='html'>In my datase i had a table which contains both numeric and characters and the table datatype was Varchar, and i have to find the min of the of the numeric value. In sql server the function ISNUMERIC(expr) was the solution to get rid of the character value.&lt;br /&gt;The ISNUMERIC function determines whether an expression is a valid numeric type. returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0. So i used the query like below&lt;br /&gt;Select min(ColName) from demo where ISNUMERIC(ColName)=1&lt;br /&gt;And i was getting my desired value.&lt;br /&gt;But one day it started  an exception in my asp.net page. And i could not find the reason.&lt;br /&gt;After a long debugging i found that it was the problem with ISNUMERIC function of sql server. The ISNUMERIC function is returning 1 for some non-numeric character like '-' i.e&lt;br /&gt;Select Isnumeric('-') returns 1 not 0.&lt;br /&gt;And it was returning '-' from the query and error in asp.net page.&lt;br /&gt;Then i tried with casting the result to int as.&lt;br /&gt;Select Cast(min(ColName) as int) from demo where ISNUMERIC(ColName)=1&lt;br /&gt;And in this way the error was solved but the min value was always 0 as Cast('-')=0&lt;br /&gt;Then i identified this abnormal characters as excluded them through the where clause.&lt;br /&gt;Select Cast(min(ColName) as int) from demo where ISNUMERIC(ColName)=1 and eadr not in('+','-','$').&lt;br /&gt;This behaviour occurs for these three charactes('+','-','$') i have found so far.&lt;br /&gt;For more information check &lt;a href="http://msdn2.microsoft.com/en-us/library/ms186272(SQL.100).aspx"&gt;this link&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-727330398828605718?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/727330398828605718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=727330398828605718' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/727330398828605718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/727330398828605718'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/04/problem-numeric-check-in-sql-server.html' title='Problem Numeric check in SQL Server'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-4607880517350155160</id><published>2008-04-09T13:52:00.001+05:30</published><updated>2008-04-16T22:58:39.193+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='UTF'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='Parsing Erroe'/><category scheme='http://www.blogger.com/atom/ns#' term='Change Encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='Encoding'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='Ascii'/><title type='text'>XML Encoding Problem In SQL Server</title><content type='html'>In a project i was sending an XML file to a SP which was written by someone. It was insering values to a master table and some details table. The SP was taking some TEXT datatype as input for the XML. Now the problem was one day we found some&lt;br /&gt;"XML parsing error: An invalid character was found in text content. sql server xml parse" error and i come to know that some datatype is having some non-ascii characters like "Ö","«" for which the error was generated.&lt;br /&gt;We were told to just avoid throughing error so that the user can continue their work. The fastest solution i came accross was to format the string before puttin into the XML.&lt;br /&gt;So i wrote a function which will take the String as input and return the ASCII string as output as below.&lt;br /&gt;public static string getUTF8String(string str) {&lt;br /&gt;char[] ch = str.ToCharArray();&lt;br /&gt;byte[] by = new byte[ch.Length * 2]; //If all char is UNicode then max byte is 2 X length System.Text.ASCIIEncoding enc = new ASCIIEncoding();&lt;br /&gt;int charUsed, byteUsed;&lt;br /&gt;bool completed;&lt;br /&gt;enc.GetEncoder().Convert(ch, 0, ch.Length, by, 0, by.Length, true, out charUsed, out byteUsed, out completed);&lt;br /&gt;string res=enc.GetString(by, 0, byteUsed);&lt;br /&gt;return res;&lt;br /&gt;}&lt;br /&gt;So the Non-Ascii character may change, but the workflow wsa not hampered.&lt;br /&gt;But the best solution is to &lt;strong&gt;&lt;span style="color:#cc0000;"&gt;change the SP and the xml sent to the SP. In the SP you should make the input parameter as NTEXT rather than TEXT and in the XML mention the encoding as UTF-16 - not UTF-8. In this way it will accept all unicode characters.&lt;/span&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-4607880517350155160?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/4607880517350155160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=4607880517350155160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4607880517350155160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4607880517350155160'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/04/xml-encoding-problem-in-sql-server.html' title='XML Encoding Problem In SQL Server'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-3573755517146265380</id><published>2008-04-01T12:37:00.000+05:30</published><updated>2008-04-01T13:09:42.567+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ajax File Upload'/><category scheme='http://www.blogger.com/atom/ns#' term='Html FIle Upload'/><category scheme='http://www.blogger.com/atom/ns#' term='File Upload'/><category scheme='http://www.blogger.com/atom/ns#' term='Ajax'/><category scheme='http://www.blogger.com/atom/ns#' term='Iframe File Upload'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>Ajax Like File Uploading</title><content type='html'>&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Place a &lt;b&gt;hiddenIFrame&lt;/b&gt; into the page and submit the form containing the file uploader (input type='file') to the hidden iframe by changing the target property of the form to the name of&lt;br /&gt;   the IFrame. Here i have made the &lt;b&gt;target&lt;/b&gt; of form (id='formUpload') to "&lt;b&gt;iframeHidden&lt;/b&gt;"&lt;br /&gt;   as my iframe name is "ifameHidden". For uploading the file you have to make the'&lt;br /&gt;   enctype' and 'method' attributes values as it is in the example. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;       I have made the action attribute of the page to UploadFile.aspx page. This is a&lt;br /&gt;       page where it counts the Files Collection of the Request Object and if it finds&lt;br /&gt;       any file in the Collection (Request.Files.Count&gt;0), it saves the file in the same&lt;br /&gt;       folder with the same name as file. The saving code is very trivial, for a real world&lt;br /&gt;       applicatio you have to be carefull while saving like name overwrite,different path&lt;br /&gt;       ect.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;   function uploadFile(id)&lt;br /&gt;   {&lt;br /&gt;       document.getElementById("formUpload").submit();&lt;br /&gt;   }&lt;br /&gt;   &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&amp;lt;iframe id="iframeHiden1" style="height:0px;width:0px;border:0"&lt;br /&gt;name="iframeHiden" src="UploadFile.aspx"&amp;gt;&amp;lt;/iframe&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;form id="formUpload" target="iframeHiden" enctype="multipart/form-data"&lt;br /&gt;action="UploadFile.aspx" method="post"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ajax Upload File In HTML Form:&amp;lt;input type="file" onchange="uploadFile('file1')"&lt;br /&gt;id="file1" name="fileUploadHTML" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;UploadFile.aspx Page Load Event&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt; protected&lt;br /&gt;void Page_Load(object sender, EventArgs e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;int noOfFile = Request.Files.Count;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (noOfFile &gt; 0)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;string path = Request.PhysicalPath.Substring(0, Request.PhysicalPath.LastIndexOf("\\")&lt;br /&gt;+ 1) + Request.Files[0].FileName;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Request.Files[0].SaveAs(path);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-3573755517146265380?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/3573755517146265380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=3573755517146265380' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3573755517146265380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/3573755517146265380'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/04/ajax-like-file-uploading.html' title='Ajax Like File Uploading'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-1671351049403837428</id><published>2008-02-21T22:27:00.000+05:30</published><updated>2008-02-21T23:02:52.962+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Infinite Session'/><category scheme='http://www.blogger.com/atom/ns#' term='Keep Session'/><category scheme='http://www.blogger.com/atom/ns#' term='Session Object'/><category scheme='http://www.blogger.com/atom/ns#' term='Session Expire'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.Net'/><title type='text'>How To Keep Session Live Till The Page Stays Open</title><content type='html'>&lt;p&gt;&lt;br /&gt;One one of my project i was told that the user will keep the browser open and will&lt;br /&gt;talk to their client for long time, which may be 1/2 hour continuous and after that&lt;br /&gt;they will come back and add some item to the page as per the discussion over the&lt;br /&gt;phone. So we have to keep the session live till that period to keep him logged in.&lt;br /&gt;The way to implement this are&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) Add the following code in &lt;span style="color:#ff0000;"&gt;web.config&lt;/span&gt; file&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&amp;lt;sessionState timeout="100"&amp;gt;&amp;lt;/sessionState&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Here timeout is in munites and sessionwill stay live upto 180 min i.e 3 hours&lt;br /&gt;(by default the timeout is 20 mins) which was enough for our purpose.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But with this way of implementation we were misusing the valuable server disk space&lt;br /&gt;for all the session variables will stay for that long time. So even if you close&lt;br /&gt;the browser the objects will stay in the server for next 3 Hours. So we implemented&lt;br /&gt;another way&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2) In the Body tag of our aspx page i put a div which is having display style attribute='None'&lt;br /&gt;so that the div does not display in the page.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And then put a IFrame inside the div and set another aspx page (KeepSession.aspx)&lt;br /&gt;as the src of the IFrame. The the page in the IFrame i make it auto refresh after&lt;br /&gt;18 mins. In this way though the session is to be expired in 20 mins (by default),&lt;br /&gt;but the KeepSession.aspx page will be reloaded in every 18 mins and the session&lt;br /&gt;will be refreshed and it will start counting the 20 mins expire time from start.&lt;br /&gt;So in this way it will stay alive for ever. Below in the quote in my NewQuote.aspx&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;::::::::::::::::::::&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div style="display:none"&amp;gt;&lt;br /&gt;&lt;span style="font-size:12;color:#ff0000;"&gt;&lt;br /&gt;&amp;lt;iframe id="redresh" src="RefreshSession.aspx" height="0" width="0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/iframe&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;form id="form1" runat="server"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div&amp;gt;YOUR PAGE CODE HERE &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;........&lt;br /&gt;&lt;br /&gt;KeepSession.aspx Page&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="KeepSession.aspx.cs"&lt;br /&gt;Inherits="KeepSession" %&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html xmlns="&lt;span style="font-size:12;color:#0000ff;"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;" &amp;gt;&amp;lt;head runat="server"&amp;gt;&amp;lt;title&amp;gt;Refresh&lt;br /&gt;Session&amp;lt;/title&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&amp;lt;meta http-equiv="refresh" content="1048" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#009900;"&gt;&amp;lt;!--Here the content value is the no of secconds&lt;br /&gt;after which the page will be reloaded automatically. Make it less than the session&lt;br /&gt;expire time --&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;form id="form1" runat="server&lt;br /&gt;&lt;br /&gt;form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-1671351049403837428?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/1671351049403837428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=1671351049403837428' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1671351049403837428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/1671351049403837428'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/02/how-to-keep-session-live-till-page.html' title='How To Keep Session Live Till The Page Stays Open'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-6206350103391253851</id><published>2008-02-06T17:27:00.000+05:30</published><updated>2008-02-06T17:38:52.737+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='View All Trigger'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='Trigger'/><title type='text'>How to view all triggers</title><content type='html'>To view the trigger from a particular database Table&lt;br /&gt;&lt;span style="color:#3366ff;"&gt;exec sp_helpTrigger @tabname='QTQuotationMaster'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you want to see all the triggers available in the database then run this&lt;br /&gt;SQL Server 2000:&lt;br /&gt;&lt;span style="color:#3366ff;"&gt;select * from sysobjects where xtype ='TR' &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SQL Server 2005:&lt;br /&gt;&lt;span style="color:#3366ff;"&gt;Select * from sys.triggers &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-6206350103391253851?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/6206350103391253851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=6206350103391253851' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6206350103391253851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/6206350103391253851'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2008/02/how-to-view-all-triggers.html' title='How to view all triggers'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1097389643353265797.post-4253431524194750564</id><published>2007-10-24T16:05:00.004+05:30</published><updated>2008-06-13T13:37:33.920+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='READTEXT'/><category scheme='http://www.blogger.com/atom/ns#' term='TEXTPTR'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server 2000'/><category scheme='http://www.blogger.com/atom/ns#' term='sql server'/><category scheme='http://www.blogger.com/atom/ns#' term='TEXTVALID'/><category scheme='http://www.blogger.com/atom/ns#' term='text'/><category scheme='http://www.blogger.com/atom/ns#' term='WRITETEXT'/><category scheme='http://www.blogger.com/atom/ns#' term='UPDATETEXT'/><category scheme='http://www.blogger.com/atom/ns#' term='ntext'/><title type='text'>Using text, ntext Data Type SQL Server</title><content type='html'>In sql server 2000 (or before ver) we uses Text,NText data type for storing very long length of string datatype. Text is suitable for non-unicode (1 byte) string and NText for unicode(2 bytes). we can't manipulate these datatype with the regular dmls, but it requires some other way because of it's storing process which is different from other data types (except Image which is stored in the same way for binary data). These datatypes's values are stored outside the row and a 16 bit pointer is tored which points to the root of the internal pointer which points the fragment of the data stored in different pages.&lt;br /&gt;We need to use READTEXT (to read), WRITETEXT ( to replace ) and UPDATETEXT (to modify) these values.&lt;br /&gt;First create a table and insert some values in it&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;CREATE TABLE TestNTextDataType ( [Id] [int] NULL , [Name] [Ntext] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]&lt;br /&gt;insert into TestNTextDataType values(1,'This is a test')&lt;br /&gt;insert into TestNTextDataType values(2,'This is second test')&lt;/span&gt;&lt;br /&gt;Declare a pointer to the 'Name' Column as&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;Declare @ptrToCol varbinary(16)&lt;br /&gt;Select @ptrToCol=TextPtr([Name]) from TestNTextDataType where [Id]=1&lt;/span&gt;&lt;br /&gt;The @ptrToCol pointer points to the NText value 'This is a test'.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;READTEXT { table.columnName @ptrToCol @offset @size } [ HOLDLOCK ]&lt;br /&gt;&lt;/strong&gt;Reads values from a column, starting from a specified offset and reading the specified number of bytes.&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;READTEXT TestNTextDataType.[Name] @ptrToCol 5 2&lt;/span&gt;&lt;br /&gt;Result: is&lt;br /&gt;The value of offset is 5 and as it is zero based it points to the 6th character 'i' and the length is 2 so the two characters starting from 'i' is returned. &lt;span style="color:#009900;"&gt;&lt;em&gt;If you pass 0 as the size then 4KB of data is read.&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms187365.aspx"&gt;Read More&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;WRITETEXT&lt;/strong&gt;&lt;/span&gt; &lt;strong&gt;{ table.columnName @ptrToCol } [ WITH LOG ] { data }&lt;br /&gt;&lt;/strong&gt;Permits minimally logged, interactive updating of an existing column. WRITETEXT overwrites any existing data in the column it affects&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;WRITETEXT TestNTextDataType.[Name] @ptrToCol 'Updated Test Final'&lt;br /&gt;&lt;/span&gt;It will update the 'This is a test' value to the new value 'Updated Test Final'. Remember that the pointer @ptrToCol points to the [Name] column of the row with the id=1 (Where clause).&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms186838.aspx"&gt;&lt;em&gt;Read More&lt;/em&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;UPDATETEXTUPDATETEXT { table.columnName @ptrToCol } { NULL @insertOffset } { NULL @deleteLength } [ WITH LOG ] [ inserted_data]&lt;br /&gt;&lt;/strong&gt;Updates an existing field. Use UPDATETEXT to change only a part of a text, ntext, or image column in place.&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;UPDATETEXT TestNTextDataType.[Name] @ptrToCol 8 4 'New String'&lt;br /&gt;&lt;/span&gt;Previous value was 'Updated Test Final' insert offset 8 points to 'T' of Test and the delete length 4 deletes the 'Test' and inserts the value 'New String'. So the result value becomes 'Updated New String Final'.&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms189466.aspx"&gt;&lt;em&gt;Read More&lt;/em&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;DataLength(Expression)&lt;/strong&gt;&lt;br /&gt;To get the length of the column value for Text,NText and Image datatype you have to use DataLength function.&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;Select DataLength([Name]) Length from TestNTextDataType where [Id]=1&lt;/span&gt;&lt;br /&gt;will return 48 as the length of 'Updated New String Final' string because the datatype is NText of the column so every charter will take 2 byte and there are 24 characters. If the datatype was Text then it will return 24. The DATALENGTH of NULL is NULL.&lt;br /&gt;&lt;br /&gt;&lt;a id="ctl00_rs1_mainContentContainer_ctl18" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe128931_cctl00_rs1_mainContentContainer_ctl18',this);" href="http://msdn.microsoft.com/en-us/library/ms188395.aspx"&gt;PATINDEX&lt;/a&gt; , &lt;a id="ctl00_rs1_mainContentContainer_ctl19" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe128931_cctl00_rs1_mainContentContainer_ctl19',this);" href="http://msdn.microsoft.com/en-us/library/ms186238.aspx"&gt;SET TEXTSIZE&lt;/a&gt;, &lt;a id="ctl00_rs1_mainContentContainer_ctl20" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe128931_cctl00_rs1_mainContentContainer_ctl20',this);" href="http://msdn.microsoft.com/en-us/library/ms187748.aspx"&gt;SUBSTRING&lt;/a&gt;, &lt;a id="ctl00_rs1_mainContentContainer_ctl24" onclick="javascript:Track('ctl00_rs1_mainContentContainer_cpe128931_cctl00_rs1_mainContentContainer_ctl24',this);" href="http://msdn.microsoft.com/en-us/library/ms187362.aspx"&gt;TEXTVALID&lt;/a&gt; are use useful functions to work with these datatypes.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Note: ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types.&lt;/strong&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1097389643353265797-4253431524194750564?l=aspxdev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspxdev.blogspot.com/feeds/4253431524194750564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1097389643353265797&amp;postID=4253431524194750564' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4253431524194750564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1097389643353265797/posts/default/4253431524194750564'/><link rel='alternate' type='text/html' href='http://aspxdev.blogspot.com/2007/10/using-text-ntext-data-type-sql-server.html' title='Using text, ntext Data Type SQL Server'/><author><name>Tarun Ghosh</name><uri>http://www.blogger.com/profile/14188725091421699499</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_7BJz2MaZ-L0/Sd174cUonwI/AAAAAAAAAN4/OZJB5tXWx8c/S220/sun2a.jpg'/></author><thr:total>6</thr:total></entry></feed>
